Closed
Description
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?