Document main actor execution requirements in Java-hosted processes

Đang mở Phù hợp với người mới
#955 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@omochi đang làm issue này rồi.

Từ ngày 6/11/2026.

  • #956 của @omochi — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, swift
Lĩnh vực
documentation

Hướng nghiên cứu

Tìm tài liệu về các API bất đồng bộ của Swift và các tiến trình do Java lưu trữ. Vì issue không nêu tên tệp cụ thể, trước tiên hãy xác định điểm bắt đầu phù hợp trong tài liệu. Giải thích rằng các lệnh gọi phụ thuộc vào trình thực thi chính của Swift có thể ngừng tiến triển tùy thuộc vào môi trường máy chủ, và có thể cần tích hợp ở phía máy chủ. Hoàn tất khi người dùng có thể tìm thấy hạn chế này và hiểu lý do nó xảy ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Swift
Star
1.3k
Fork
127
Merge trung bình
1 giờ 6 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của swiftlang/swift-java

Tất cả issue của swiftlang/swift-java

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.