Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Asynchronous calls in JSClosure #157

Copy link
Copy link
@mhavu

Description

@mhavu
Issue body actions

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?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.