Skip to content

[pigeon] Annotate event channel APIs with @MainActor - #13680

Closed
vikrant-sainii wants to merge 4 commits into
flutter:mainfrom
vikrant-sainii:fix195012
Closed

vikrant-sainii wants to merge 4 commits into
flutter:mainfrom
vikrant-sainii:fix195012

Conversation

@vikrant-sainii

@vikrant-sainii vikrant-sainii commented Nov 16, 2026 •

Copy link
Copy Markdown

This PR addresses flutter/flutter#195012.

Pigeon's generated Swift event-channel APIs currently do not explicitly declare their main-actor isolation. Although Flutter invokes event-channel callbacks on the main thread, developers implementing event handlers may need workarounds such as MainActor.assumeIsolated. This PR makes the generated event-channel APIs explicitly main-actor isolated.

Changes:

  • Annotated PigeonEventChannelWrapper and PigeonStreamHandler with @MainActor.
  • Added @preconcurrency compatibility for FlutterStreamHandler.
  • Annotated generated setStreamHandler and register APIs with @MainActor.
  • Added a Swift generator regression test.
  • Updated the Swift test plugin and compile test for the new actor-isolation requirements.

Testing:

  • The following tests were run locally and passed:
  • Swift generator tests — 63 passed.
  • iOS Swift unit tests — 82 passed.
  • iOS Swift integration tests — 683 passed.
  • macOS Swift unit tests — 16 passed.
  • macOS Swift integration tests — 682 passed, 1 skipped.

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

@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 the Pigeon package version to 30.0.4 and introduces @mainactor isolation to generated Swift event-channel APIs and their associated handlers. It also updates the test plugin to use @mainactor for registration and lifecycle methods, and includes a new test case to verify the @mainactor isolation in generated code. The review feedback suggests improving Swift formatting for trailing closures and removing a redundant helper method for checking the main thread, as Thread.isMainThread is directly accessible in asynchronous contexts.

@tarrinneal

tarrinneal commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Closing as superceded by #13704, thank you for your time and effort making this contribution.

@tarrinneal tarrinneal closed this Nov 18, 2026
@vikrant-sainii

Copy link
Copy Markdown
Author

Thanks for the clarification! I understand that #13704 replaces the existing event-channel architecture and supersedes this approach. I appreciate your time reviewing my contribution. I'll follow the progress of the new implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants