Skip to content

JSClosure.async doesn't work at all #224

Closed
@MihaelIsaev

Description

@MihaelIsaev

Hi guys, I'm trying to use JSClosure.async but it never called, while JSClosure works well in the same place.
I added a lot of prints under the hood in every call related to JSClosure.async but none of them has been called.

import JavaScriptKit

@main
public struct CartonApp {
    public private(set) var text = "Hello, World!"

    public static func main() async {
        print(CartonApp().text)
        if let docObj = JSObject.global.document.object, let bodyObj = JSObject.global.document.jsValue.body.object {
            var button = JSObject.global.document.createElement.function?.callAsFunction(this: docObj, "button").jsValue
            button?.innerText = "Click me".jsValue
            JSObject.global.document.jsValue.body.appendChild.function?.callAsFunction(this: bodyObj, button)
            if let buttonObj = button?.object {
                button?.addEventListener.function?.callAsFunction(this: buttonObj, "click", JSClosure.async({ args in
                    print("clicked async") // never called
                    return .undefined
                }))
            }
        }
    }
}

Could you please tell me if there is a bug or I'm using it wrong? If I'm using it wrong could you please provide me with any working example that I could easily launch.

Thanks in advance.

@MaxDesiatov @mjburghard @PatrickPijnappel @valeriyvan @yonihemi swiftwasm/swift#5376

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions