from() doesn't flatten AsyncGenerator from async factory functions - requires defer workaround
#7566
tomsseisums
started this conversation in
Ideas / Feature request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Working with Gemini API, specifically streaming endpoints that work with
AsyncGenerators, I stumbled upon an issue where if anAsyncGeneratoris returned from anasyncfactory function,fromdoesn't flatten it, requiring to jump throughdeferhoops.Real-world Use Case
This pattern is common when working with AI/ML streaming APIs. For example, with Google's Gemini API:
Current Workaround
The current solution requires using
defer:Expected Behavior
It would be more intuitive if
from()could detect when it receives aPromise<AsyncIterable>and handle it appropriately, similar to how it already handles:AsyncIterable/AsyncGeneratorPromise<T>(emits the resolved value)The Root Cause
Currently, when
from()receives aPromise, it treats it as "emit the resolved value" rather than checking if that resolved value is itself anAsyncIterablethat should be iterated.Beta Was this translation helpful? Give feedback.
All reactions