feat!: return IAsyncEnumerable from Watch and OnChange#43
Merged
Conversation
Chriztiaan
reviewed
Feb 23, 2026
Collaborator
Chriztiaan
left a comment
There was a problem hiding this comment.
Happy with the changes from my side.
Chriztiaan
previously approved these changes
Feb 23, 2026
Collaborator
|
Changelog entry |
Chriztiaan
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
TODOS
ListenwithListenAsyncfor most/all usesDescription
Most SDKs have moved away from the callback-based APIs and towards async iterators/enumerators. This comes with a few ergonomic benefits and a few practical ones, including the ability to subscribe to changes lazily. Using an async iterator means users can decide when they want to process the next item in the stream, whereas with callbacks, changes are pushed eagerly and are processed when we are ready instead of when the caller is ready.
I want to avoid maintaining two APIs for this, as doing so could lead to a situation like the one in the Javascript SDK, where both approaches need to be maintained in order to maintain API stability guarantees. This makes the implementation code for watched queries in JS quite difficult to follow. Plus, the eager-fetching behaviour from the old callback style can still be achieved via a background task, so the callback syntax is somewhat obsoleted by the async iterator syntax.
This PR replaces the callback-based maintenance nightmare that was the old Watch and OnChange implementations and return types with methods that return
IAsyncEnumerable's, using the Kotlin SDK as a reference. IMO, this makes Watch both more flexible and easier to maintain.Example
Old syntax
New syntax