Async reactor API for WASI exports #335
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this API is to merge the functionality of both the
WASIReactorand theWASIWorkerHostby having allWASIexports be wrapped as aPromiseso long-running function calls won't halt any functionality in the main context. In addition, the API enforces a specification for how export argument data is handled by theWASIReactorWorkerHostso that the underlyingWebWorkercan pass arguments to anyWASIexport with type safety on the following types:Int32,Uint32,string,Int32Array,Uint32Array. It achieves this by tagging all arguments with a distinct type tag as they're stored in theWASImemory buffer (exports.memory.buffer). The exportedWASIfunction will then need to parse the memory buffer for those arguments and repeat the same process for any values it would like to return.Depicted above is a sample implementation showcasing how to call an export. The parameters for constructing the
WASIReactorWorkerHostslightly vary compared toWASIReactorandWASIWorkerHostby enforcing a start index in the memory buffer for which all arguments should begin storing data (the8) as well as an error handler function for the error code that should be returned by the exported function.This specification is quite verbose and enforces a lot of work to be done by the
WASMbinary creator to ensure the binary is properly reading from the memory the way the API is storing in it. However, with well laid out documentation, I still think this approach is quite effective overall and establishes good calling conventions that developers should abide by until theWASMstandard is able to support more diverse types.