swiftwasm / swift

WebAssembly support for the Swift programming language
https://swiftwasm.org
1.28k stars 28 forks source link

Thread and RunLoopMode.common in not available on WASM #5581

Open Kyle-Ye opened 2 months ago

Kyle-Ye commented 2 months ago

Encounter some Thread related WASM error recently.

import Foundation

// Works on Ubuntu and macOS
@inline(__always)
func performOnMainThread(_ block: @escaping () -> Void) {
    if Thread.isMainThread {
        block()
    } else {
        RunLoop.main.perform(inModes: [.common], block: block)
    }
}
ThreadUtils.swift:15:41: error: reference to member 'common' cannot be resolved without a contextual type
        RunLoop.main.perform(inModes: [.common], block: block)
                                        ^
ThreadUtils.swift:12:8: error: cannot find 'Thread' in scope
    if Thread.isMainThread {

Is this an expected behavior and #5548 already keeps track of the issue?

kateinoigakukun commented 2 months ago

This is expected since we don't enable any RunLoop feature at this moment. Might be unblocked after porting libdispatch with threading support.