Document main actor execution requirements in Java-hosted processes
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
查找介绍 Swift 异步 API 和由 Java 托管的进程的文档。由于 issue 没有指定具体文件,请先找到相关文档的入口。说明依赖 Swift 主执行器的调用可能会因宿主环境而停止推进,并且可能需要在宿主端进行集成。用户能够发现这一限制并理解其发生原因后,即算完成。
由索引模型根据 Issue 内容生成。
描述
Problem
swift-java can export asynchronous Swift functions annotated with @MainActor to Java. However, depending on the host environment, a call may stop making progress when it switches to the main actor. This can happen not only when the exported function is itself annotated with @MainActor, but also when a Swift library uses the main actor internally.
It is natural for swift-java users to expect @MainActor, a standard Swift language feature, to work as usual. As a result, they may not immediately recognize the cause of the problem. The issue is also technically complex, making it difficult for many users to address.
For an example, see:
Technical background
This problem occurs when work submitted to Swift's main executor is not executed in the host environment.
When a Swift executable is launched, its entry point and platform environment are responsible for running asynchronous work and event loops. In contrast, when a Java application calls Swift, the Java host manages the process entry point and event loop. swift-java generates bindings for Swift libraries used in that process. Depending on the host environment, additional integration may therefore be needed to run Swift's main executor.
For example, swift-android-native provides an implementation that uses the private libdispatch API _dispatch_main_queue_callback_4CF to process the Dispatch main queue used by Swift's main executor on the Android main looper.
Proposal
Ideally, users should be able to use Swift code that relies on @MainActor without additional effort. However, swift-java does not own the host process's entry point or event loop, and the necessary integration depends on the host environment and application configuration.
As a first step, I propose updating the documentation so that users can discover this limitation and understand that host-side integration may be needed. I am preparing a PR for the documentation update.
Future directions
In the future, it may be worth considering whether swift-java should provide an implementation to run the main executor. For example, one possibility would be to start a dedicated thread at JNI_OnLoad to drive the Swift main executor.
- 主要语言
- Swift
- 星标
- 1.3k
- 派生
- 127
- 平均合并
- 1 小时 6 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swiftlang/swift-java 的其他 Issue
-
wrap-java: Optional convenience methods can fail to compile when a parameter shadows the method name未关闭
难度 2/5 1-3 小时 新手友好度 70/100
swiftlang/swift-java#945 ·
维护者通常 1 天内回复
-
android
难度 2/5 1-3 小时 新手友好度 75/100
swiftlang/swift-java#663 · 4 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
swiftlang/swift-java#949 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
swiftlang/swift-java#948 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 54/100
swiftlang/swift-java#947 ·
维护者通常 1 天内回复
查看 swiftlang/swift-java 的全部 Issue
相似的 Issue
-
area: agents follow-up
难度 2/5 1-3 小时 新手友好度 77/100
manaflow-ai/cmux#37234 · 1 条评论 ·
维护者通常 1 天内回复
-
bug product / functions
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 61/100
JWhite212/SignalLadder#215 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug javascript
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复