emscripten-core / emscripten-core/emscripten
Generate both sync and async modules
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
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](https://github.com/zemlyansky/arima) I run emcc two times with `BINARYEN_ASYNC_COMPILATION=0` and `BINARYEN_ASYNC_COMPILATION=1` generating two different `.js` files with `Module`s. 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 `require`d 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:
```javascript
// Sync
const module = Module({ wasmBinary: bin, async: False })
// Async
Module({ wasmBinary: bin, async: True }).then(module => {
...
})
```
Contributor guide
Assessment
This issue has not been assessed yet.