Description
Bug report
Describe the bug
When utilizing the experimental functions. _invokeWithStreamedResponse
method (introduced in #346), the returned AsyncThrowingStream
never yields any data to the consumer.
let events = supabase.functions._invokeWithStreamedResponse("some-sse-edge-function", options: options)
for try await data in events {
// never executed
}
To Reproduce
Initialize _invokeWithStreamedResponse
with an edge-function configured to send a text stream (e.g. the Deno SSE template should suffice).
Expected behavior
As bytes are decoded from the underlying NSURLSession
they are yielded to the consumer.
System information
- OS: macOS 14.4.1
- Version of supabase-swift: 2.13.2
- iOS version: 17.0.1
Additional context
The current implementation of _invokeWithStreamedResponse
creates a session.dataTask
with a callback:
supabase-swift/Sources/Functions/FunctionsClient.swift
Lines 201 to 217 in fa8db0c
however, it is also specifying a URLSession
delegate which is responsible for yielding data:
According to the docs, if a dataTask
is specified with a callback, then the delegate is never used, which would explain why values are never yielded:
By using the completion handler, the task bypasses calls to delegate methods for response and data delivery, and instead provides any resulting NSData, URLResponse, and NSError objects inside the completion handler. Delegate methods for handling authentication challenges, however, are still called.
Patching the library to no longer use the callback resolved my issue: kirkbyo@70959a3