Skip to content

Allow async function to be imported/exported #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eduardomourar opened this issue Feb 20, 2023 · 5 comments
Closed

Allow async function to be imported/exported #39

eduardomourar opened this issue Feb 20, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@eduardomourar
Copy link
Contributor

There are certain cases where the host/guest implementation needs to pass an asynchronous function. Can this be supported in the JavaScript codegen even when the WIT definition has its signature as synchronous?

@guybedford
Copy link
Collaborator

It is up to the implementation to ensure it provides a sync API. In Node.js it is always possible to syncify any call though on the implementaiton side by creating a worker thread and using atomics to synchronously wait on a shared lock in the worker that is performing asynchronous work. Usually it's best to just have a fully sync implementation though.

@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Oct 18, 2023
@DougAnderson444
Copy link
Contributor

Have you guys seen the work Joel Dice did here: https://github.com/dicej/isyswasfa/tree/main

It's very experimental at this point and only in Rust, but looks like it will be very useful when he gets to JavaScript.

@guybedford
Copy link
Collaborator

Yes, we will follow in this path in the Jco project, where functions may support both sync and async variants depending on the canon ABI option passed. Preview 3 support is a little way off though still.

If anyone is interested in prototyping in the mean time along a similar lines, work here would be welcome.

@DougAnderson444
Copy link
Contributor

linking here for reference: dicej/isyswasfa#1 (comment)

@vados-cosmonic
Copy link
Collaborator

Hey @eduardomourar with the merge of experimental JSPI integration this should be possible in jco with NodeJS, and as far as the work to support Async components is concerned (which is similar, but different) that will be covered by #617 (It's been a while but heads up @DougAnderson444 if you're still interested!)

As extra context, see #551 which contains some pieces of an alternate approach (asyncify), and updates to the browser bindings. We hope to get the experimental browser-side bindings updated but there's not a great timeline just yet on when that PR will be reformulated/can be finished (if it will even make sense, given growing support for JSPI).

I'll close this issue for now -- please feel free to comment if you think it should be re-opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants