Skip to content

[pigeon] Replace @EventChannelApi with idiomatic Stream<T> methods on @HostApi - #13704

Open
tarrinneal wants to merge 15 commits into
flutter:mainfrom
tarrinneal:pigeon-idiomatic-streams
Open

tarrinneal wants to merge 15 commits into
flutter:mainfrom
tarrinneal:pigeon-idiomatic-streams

Conversation

@tarrinneal

Copy link
Copy Markdown
Contributor

Replaces @EventChannelApi (along with KotlinEventChannelOptions and SwiftEventChannelOptions) with idiomatic Stream<T> return types directly on @HostApi() methods across the Dart, Kotlin, and Swift generators:

  • Default structured-concurrency signatures: Generates Flow<T> in Kotlin and AsyncThrowingStream<T, Error> in Swift, automatically cancelling the underlying coroutine or Task when the Dart StreamSubscription is cancelled.
  • @asyncCallback event sinks: Annotating a Stream<T> method with @asyncCallback generates a thread-safe PigeonEventSink<T> (success, error, endOfStream) parameter and returns an optional cancellation handle (AutoCloseable? in Kotlin, (() -> Void)? in Swift) for callback- or listener-based SDKs.
  • Typed parameters & independent subscriptions: Supports typed positional/named parameters on stream methods, multiple stream APIs/files without shared-class collisions, and multiplexed per-listener subscriptions so concurrent listeners on the same method/channel do not clobber one another.

Fixes flutter/flutter#195480
Fixes flutter/flutter#162828
Fixes flutter/flutter#179154
Fixes flutter/flutter#195012 (obsoletes PigeonEventChannelWrapper / *StreamHandler subclasses in favor of @HostApi protocols; opt-in @HostApi actor annotations are tracked in flutter/flutter#194655)

Pre-Review Checklist

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-assist bot 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

  1. 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

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Nov 18, 2026
@github-actions github-actions Bot added the P2 Important issues not at the top of the work list label Nov 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tarrinneal
tarrinneal marked this pull request as draft November 18, 2026 05:03
@tarrinneal
tarrinneal marked this pull request as ready for review November 19, 2026 20:12

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dkwingsmt
dkwingsmt self-requested a review November 19, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD p: pigeon P2 Important issues not at the top of the work list platform-android platform-ios platform-macos

Projects

None yet

1 participant