@@ -3,6 +3,7 @@ export const createWasiBrowserBinding = (
3
3
initialMemory = 4000 ,
4
4
maximumMemory = 65536 ,
5
5
fs = false ,
6
+ asyncInit = false ,
6
7
) => {
7
8
const fsImport = fs ? `import { memfs } from '@napi-rs/wasm-runtime/fs'` : ''
8
9
const wasiCreation = fs
@@ -25,8 +26,15 @@ const __wasi = new __WASI({
25
26
? ` worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs))\n`
26
27
: ''
27
28
29
+ const emnapiInstantiateImport = asyncInit
30
+ ? `instantiateNapiModule as __emnapiInstantiateNapiModule`
31
+ : `instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync`
32
+ const emnapiInstantiateCall = asyncInit
33
+ ? `await __emnapiInstantiateNapiModule`
34
+ : `__emnapiInstantiateNapiModuleSync`
35
+
28
36
return `import {
29
- instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync ,
37
+ ${ emnapiInstantiateImport } ,
30
38
getDefaultContext as __emnapiGetDefaultContext,
31
39
WASI as __WASI,
32
40
createOnMessage as __wasmCreateOnMessageForFsProxy,
@@ -49,7 +57,7 @@ const {
49
57
instance: __napiInstance,
50
58
module: __wasiModule,
51
59
napiModule: __napiModule,
52
- } = __emnapiInstantiateNapiModuleSync (__wasmFile, {
60
+ } = ${ emnapiInstantiateCall } (__wasmFile, {
53
61
context: __emnapiContext,
54
62
asyncWorkPoolSize: 4,
55
63
wasi: __wasi,
0 commit comments