Skip to content

Asynchronous calls in JSClosure #157

Closed
@mhavu

Description

@mhavu

What is the best way to handle calls to asynchronous code inside a JSClosure, especially if one needs to return the result of such call from the JSClosure? Consider the following example:

let closure = .object(JSClosure { (arguments: [JSValue]) in
    guard let url = arguments.first?.string else {
        return JSValue.undefined
    }
    return await fetch(url)
})

This results in the following error:

cannot pass function of type '([JSValue]) async -> JSValue' to parameter expecting synchronous function type

The reason is obvious, but is there a nice way to work around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions