jco icon indicating copy to clipboard operation
jco copied to clipboard

Allow async function to be imported/exported

Open eduardomourar opened this issue 2 years ago • 4 comments

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?

eduardomourar avatar Feb 20 '23 18:02 eduardomourar

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.

guybedford avatar Feb 20 '23 19:02 guybedford

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.

DougAnderson444 avatar Feb 27 '24 20:02 DougAnderson444

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.

guybedford avatar Feb 27 '24 21:02 guybedford

linking here for reference: https://github.com/dicej/isyswasfa/issues/1#issuecomment-1974838959

DougAnderson444 avatar Jun 19 '24 18:06 DougAnderson444