Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asynchronous WasmThemis initialization (#507)
It turns out that WebAssembly is compiled and loaded asynchronously [1]. There is an option for synchronous compilation, but Chrome and Electron support only asynchronous loading. This means that one cannot simply call C functions. We need to wait for WebAssembly to be compiled and Emscripten runtime to boot. This is performed automatically if the whole application is compiled by Emscripten, but Themis is a library. Emscripten provides an "onRuntimeInitialized" callback which is called when Emscripten startup is complete and C functions can be called. Expose an interface to this callback as JavaScript promise which is resolved once initialization is complete. The users should call Themis functions only after this promise is resolved. (Alternatively, they can wait for a second or two.) This behavior is not reproduced by unit tests because Mocha launches asynchronously too and it manages to start testing after WasmThemis loading is complete. But we can test that the promise is resolved. [1]: https://emscripten.org/docs/compiling/WebAssembly.html#wasm-files-and-compilation
- Loading branch information