-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
What is the right way to generate a package that works in Node.js or Web Workers without extra Promises and can be used in Chrome (asynchronously)?
Currently in arima.js I run emcc two times with BINARYEN_ASYNC_COMPILATION=0 and BINARYEN_ASYNC_COMPILATION=1 generating two different .js files with Modules. The package exposes two endpoints: synchronous arima for Node.js (or Web Workers, Firefox only) using sync Module compilation, and Promise-based arima/async for all browsers including Chrome. In both cases the generated wasm file is wrapped in its own js file that can be required and passed to Module then bundled (this prevents extra fetching).
So, this approach works, but feels hackish (it compiles the same wasm file two times). Maybe it makes sense to generate two Module files or one universal if BINARYEN_ASYNC_COMPILATION is not set? For example:
// Sync
const module = Module({ wasmBinary: bin, async: False })
// Async
Module({ wasmBinary: bin, async: True }).then(module => {
...
})