Repository navigation
[pigeon] Replace @EventChannelApi with idiomatic Stream<T> methods on @HostApi - #13704
tarrinneal wants to merge 15 commits into
Conversation
…n-idiomatic-streams
There was a problem hiding this comment.
Code Review
This pull request removes the @EventChannelApi annotation in Pigeon, replacing it with support for Stream<T> return types on @HostApi methods. The Dart, Kotlin, and Swift generators are updated to produce structured-concurrency streams (Flow<T> in Kotlin and AsyncThrowingStream<T, Error> in Swift) by default, or callback-based event sinks when annotated with @asyncCallback. The changes also update the AST, validation logic, example code, and integration tests, and bump the package version to 31.0.0. No review comments were provided, and there is no feedback to offer.
There was a problem hiding this comment.
Code Review
This pull request updates Pigeon to version 31.0.0, introducing a breaking change that removes @EventChannelApi in favor of supporting Stream<T> return types directly on @HostApi methods across Dart, Kotlin, and Swift. This enables streaming sequences of values from the host platform to Flutter using either structured concurrency (Flow in Kotlin, AsyncThrowingStream in Swift) or callback-based event sinks when annotated with @asyncCallback. The AST, generators, validation logic, examples, and integration tests have been updated to support this new streaming model. Feedback on the changes suggests using isAsynchronousCallback instead of isUseCallback in the parser validation logic to maintain consistency with the rest of the codebase.
Replaces
@EventChannelApi(along withKotlinEventChannelOptionsandSwiftEventChannelOptions) with idiomaticStream<T>return types directly on@HostApi()methods across the Dart, Kotlin, and Swift generators:Flow<T>in Kotlin andAsyncThrowingStream<T, Error>in Swift, automatically cancelling the underlying coroutine orTaskwhen the DartStreamSubscriptionis cancelled.@asyncCallbackevent sinks: Annotating aStream<T>method with@asyncCallbackgenerates a thread-safePigeonEventSink<T>(success,error,endOfStream) parameter and returns an optional cancellation handle (AutoCloseable?in Kotlin,(() -> Void)?in Swift) for callback- or listener-based SDKs.Fixes flutter/flutter#195480
Fixes flutter/flutter#162828
Fixes flutter/flutter#179154
Fixes flutter/flutter#195012 (obsoletes
PigeonEventChannelWrapper/*StreamHandlersubclasses in favor of@HostApiprotocols; opt-in@HostApiactor annotations are tracked in flutter/flutter#194655)Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2