Document main actor execution requirements in Java-hosted processes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- documentation
Research direction
Find the documentation covering asynchronous Swift APIs and Java-hosted processes; the issue does not name a specific file, so first locate the relevant documentation entry point. Explain that calls relying on Swift's main executor may stop making progress depending on the host environment, and that host-side integration may be required. Done when users can discover this limitation and understand why it occurs.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Swift
- Stars
- 1.3k
- Forks
- 127
- Avg merge
- 1h 6m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from swiftlang/swift-java
-
wrap-java: Optional convenience methods can fail to compile when a parameter shadows the method nameOpen
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
swiftlang/swift-java#945 ·
Maintainers usually reply within 1 day
-
android
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
swiftlang/swift-java#663 · 4 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
swiftlang/swift-java#949 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
swiftlang/swift-java#948 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 54/100
swiftlang/swift-java#947 ·
Maintainers usually reply within 1 day
All issues in swiftlang/swift-java
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 61/100
JWhite212/SignalLadder#215 ·
Maintainers usually reply within 1 day
-
enhancement mac
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
-
feat: 앱 정보에 개인정보처리방침과 고객지원 연결Possibly taken @xrpjwk8 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
DeveloperAcademy-POSTECH/2026-C6-A13-Hear-I-am#120 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
michaelnisi/hanstholm#246 · 1 comment ·
Maintainers usually reply within 1 day
-
area:shell order:4 status:ready type:chore
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
krystianslowik/arkt#739 ·
Maintainers usually reply within 1 day