{"_id":"@emnapi/wasi-threads","_rev":"4499106","name":"@emnapi/wasi-threads","description":"WASI threads proposal implementation in JavaScript","dist-tags":{"latest":"1.2.1"},"maintainers":[{"name":"toyobayashi","email":""}],"time":{"modified":"2026-04-09T01:41:25.000Z","created":"2024-05-19T06:29:20.305Z","1.2.1":"2026-04-02T10:11:08.255Z","1.2.0":"2026-03-12T08:47:55.227Z","1.1.0":"2025-08-28T09:32:28.975Z","1.0.4":"2025-07-18T08:41:13.577Z","1.0.3":"2025-07-07T14:33:43.222Z","1.0.2":"2025-04-15T16:07:03.666Z","1.0.1":"2024-05-19T08:17:47.304Z","1.0.0":"2024-05-19T06:29:20.305Z"},"users":{},"author":{"name":"toyobayashi"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"versions":{"1.2.1":{"name":"@emnapi/wasi-threads","version":"1.2.1","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"gitHead":"8037eb8107ae0c74f99c3fe0b045d5cf3f438ff9","_id":"@emnapi/wasi-threads@1.2.1","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"shasum":"28fed21a1ba1ce797c44a070abc94d42f3ae8548","size":39359,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.2.1.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:05470976-075f-4b7b-8d48-b3daf030dc03"}},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wasi-threads_1.2.1_1775124668108_0.3829109694047361"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-04-02T10:11:08.255Z","publish_time":1775124668255,"_source_registry_name":"default","_cnpm_publish_time":1775124668255},"1.2.0":{"name":"@emnapi/wasi-threads","version":"1.2.0","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"gitHead":"c9743cf573e52c5b4d31d7369c752b652b29fe9e","_id":"@emnapi/wasi-threads@1.2.0","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"shasum":"a19d9772cc3d195370bf6e2a805eec40aa75e18e","size":39320,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.2.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:05470976-075f-4b7b-8d48-b3daf030dc03"}},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wasi-threads_1.2.0_1773305275085_0.6219428515424414"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-03-12T08:47:55.227Z","publish_time":1773305275227,"_source_registry_name":"default","_cnpm_publish_time":1773305275227},"1.1.0":{"name":"@emnapi/wasi-threads","version":"1.1.0","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"_id":"@emnapi/wasi-threads@1.1.0","gitHead":"3a1cf8da7158477d52d3c298485a5b4a4db42d09","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"60b2102fddc9ccb78607e4a3cf8403ea69be41bf","size":39274,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.1.0.tgz"},"_npmUser":{"name":"toyobayashi","email":"lifenglin314@outlook.com"},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wasi-threads_1.1.0_1756373548762_0.7307111935503441"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-08-28T09:32:28.975Z","publish_time":1756373548975,"_source_registry_name":"default","_cnpm_publish_time":1756373548975},"1.0.4":{"name":"@emnapi/wasi-threads","version":"1.0.4","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"_id":"@emnapi/wasi-threads@1.0.4","gitHead":"4afb0e72e28486a073e55d8fa2e00c9ea916d0f5","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"703fc094d969e273b1b71c292523b2f792862bf4","size":38246,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.0.4.tgz"},"_npmUser":{"name":"toyobayashi","email":"lifenglin314@outlook.com"},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wasi-threads_1.0.4_1752828073367_0.4092440293040531"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-07-18T08:41:13.577Z","publish_time":1752828073577,"_source_registry_name":"default","_cnpm_publish_time":1752828073577},"1.0.3":{"name":"@emnapi/wasi-threads","version":"1.0.3","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"_id":"@emnapi/wasi-threads@1.0.3","gitHead":"92d5bba8c7c3da32d9aa9d2571555f517b847d4e","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"83fa228bde0e71668aad6db1af4937473d1d3ab1","size":38270,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.0.3.tgz"},"_npmUser":{"name":"toyobayashi","email":"lifenglin314@outlook.com","actor":{"name":"toyobayashi","email":"lifenglin314@outlook.com","type":"user"}},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wasi-threads_1.0.3_1751898822851_0.0903609685699478"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-07-07T14:33:43.222Z","publish_time":1751898823222,"_source_registry_name":"default","_cnpm_publish_time":1751898823222},"1.0.2":{"name":"@emnapi/wasi-threads","version":"1.0.2","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"_id":"@emnapi/wasi-threads@1.0.2","gitHead":"90c4c1b1358851d401dd162c5d1925a2dcb2e397","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"977f44f844eac7d6c138a415a123818c655f874c","size":38057,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.0.2.tgz"},"_npmUser":{"name":"toyobayashi","email":"lifenglin314@outlook.com"},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wasi-threads_1.0.2_1744733223477_0.9346622564921898"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-04-15T16:07:03.666Z","publish_time":1744733223666,"_source_registry_name":"default","_cnpm_publish_time":1744733223666},"1.0.1":{"name":"@emnapi/wasi-threads","version":"1.0.1","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"_id":"@emnapi/wasi-threads@1.0.1","gitHead":"f1fe5df18be4f35968381bc9be5df71942fe7165","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"d7ae71fd2166b1c916c6cd2d0df2ef565a2e1a5b","size":38164,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.0.1.tgz"},"_npmUser":{"name":"toyobayashi","email":"lifenglin314@outlook.com"},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wasi-threads_1.0.1_1716106667079_0.9628386566243541"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-19T08:17:47.304Z","publish_time":1716106667304,"_source_registry_name":"default","_cnpm_publish_time":1716106667304},"1.0.0":{"name":"@emnapi/wasi-threads","version":"1.0.0","description":"WASI threads proposal implementation in JavaScript","main":"index.js","module":"./dist/wasi-threads.esm-bundler.js","types":"./dist/wasi-threads.d.ts","sideEffects":false,"exports":{".":{"types":{"module":"./dist/wasi-threads.d.ts","import":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.d.ts"},"module":"./dist/wasi-threads.esm-bundler.js","import":"./dist/wasi-threads.mjs","default":"./index.js"},"./dist/wasi-threads.cjs.min":{"types":"./dist/wasi-threads.d.ts","default":"./dist/wasi-threads.cjs.min.js"},"./dist/wasi-threads.min.mjs":{"types":"./dist/wasi-threads.d.mts","default":"./dist/wasi-threads.min.mjs"}},"dependencies":{"tslib":"^2.4.0"},"scripts":{"build":"node ./script/build.js","build:test":"node ./test/build.js","test":"node ./test/index.js"},"repository":{"type":"git","url":"git+https://github.com/toyobayashi/emnapi.git"},"author":{"name":"toyobayashi"},"license":"MIT","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"homepage":"https://github.com/toyobayashi/emnapi#readme","publishConfig":{"access":"public"},"_id":"@emnapi/wasi-threads@1.0.0","gitHead":"696f3e8b74a6974b3ccbc1b8c6b78830a99b780f","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"shasum":"595309a3ccff2870635ee92e24d3013eb9ff34e6","size":37084,"noattachment":false,"key":"/@emnapi/wasi-threads/-/@emnapi/wasi-threads-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@emnapi/wasi-threads/download/@emnapi/wasi-threads-1.0.0.tgz"},"_npmUser":{"name":"toyobayashi","email":"lifenglin314@outlook.com"},"directories":{},"maintainers":[{"name":"toyobayashi","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wasi-threads_1.0.0_1716100160135_0.31306629634876315"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-19T06:29:20.305Z","publish_time":1716100160305,"_source_registry_name":"default","_cnpm_publish_time":1716100160305}},"readme":"# @emnapi/wasi-threads\n\nThis package makes [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads) based WASI modules work in Node.js and browser.\n\n## Quick Start\n\n`index.html`\n\n```html\n<script src=\"./node_modules/@tybys/wasm-util/dist/wasm-util.js\"></script>\n<script src=\"./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js\"></script>\n<script src=\"./index.js\"></script>\n```\n\nIf your application will block browser main thread (for example `pthread_join`), please run it in worker instead.\n\n```html\n<script>\n  // pthread_join (Atomics.wait) cannot be called in browser main thread\n  new Worker('./index.js')\n</script>\n```\n\n`index.js`\n\n```js\nconst ENVIRONMENT_IS_NODE =\n  typeof process === 'object' && process !== null &&\n  typeof process.versions === 'object' && process.versions !== null &&\n  typeof process.versions.node === 'string';\n\n(function (main) {\n  if (ENVIRONMENT_IS_NODE) {\n    main(require)\n  } else {\n    if (typeof importScripts === 'function') {\n      importScripts('./node_modules/@tybys/wasm-util/dist/wasm-util.js')\n      importScripts('./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js')\n    }\n    const nodeWasi = { WASI: globalThis.wasmUtil.WASI }\n    const nodeWorkerThreads = {\n      Worker: globalThis.Worker\n    }\n    const _require = function (request) {\n      if (request === 'node:wasi' || request === 'wasi') return nodeWasi\n      if (request === 'node:worker_threads' || request === 'worker_threads') return nodeWorkerThreads\n      if (request === '@emnapi/wasi-threads') return globalThis.wasiThreads\n      throw new Error('Can not find module: ' + request)\n    }\n    main(_require)\n  }\n})(async function (require) {\n  const { WASI } = require('wasi')\n  const { Worker } = require('worker_threads')\n  const { WASIThreads } = require('@emnapi/wasi-threads')\n\n  const wasi = new WASI({\n    version: 'preview1'\n  })\n  const wasiThreads = new WASIThreads({\n    wasi,\n\n    /**\n     * avoid Atomics.wait() deadlock during thread creation in browser\n     * see https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size\n     */\n    reuseWorker: ENVIRONMENT_IS_NODE\n      ? false\n      : {\n          size: 4 /** greater than actual needs (2) */,\n          strict: true\n        },\n\n    /**\n     * Synchronous thread creation\n     * pthread_create will not return until thread worker actually starts\n     */\n    waitThreadStart: typeof window === 'undefined' ? 1000 : false,\n\n    onCreateWorker: () => {\n      return new Worker('./worker.js', {\n        execArgv: ['--experimental-wasi-unstable-preview1']\n      })\n    }\n  })\n  const memory = new WebAssembly.Memory({\n    initial: 16777216 / 65536,\n    maximum: 2147483648 / 65536,\n    shared: true\n  })\n  let input\n  const file = 'path/to/your/wasi-module.wasm'\n  try {\n    input = require('fs').readFileSync(require('path').join(__dirname, file))\n  } catch (err) {\n    const response = await fetch(file)\n    input = await response.arrayBuffer()\n  }\n  let { module, instance } = await WebAssembly.instantiate(input, {\n    env: { memory },\n    wasi_snapshot_preview1: wasi.wasiImport,\n    ...wasiThreads.getImportObject()\n  })\n\n  wasiThreads.setup(instance, module, memory)\n  await wasiThreads.preloadWorkers()\n\n  if (typeof instance.exports._start === 'function') {\n    return wasi.start(instance)\n  } else {\n    wasi.initialize(instance)\n    // instance.exports.exported_wasm_function()\n  }\n})\n```\n\n`worker.js`\n\n```js\n(function (main) {\n  const ENVIRONMENT_IS_NODE =\n    typeof process === 'object' && process !== null &&\n    typeof process.versions === 'object' && process.versions !== null &&\n    typeof process.versions.node === 'string'\n\n  if (ENVIRONMENT_IS_NODE) {\n    const _require = function (request) {\n      return require(request)\n    }\n\n    const _init = function () {\n      const nodeWorkerThreads = require('worker_threads')\n      const parentPort = nodeWorkerThreads.parentPort\n\n      parentPort.on('message', (data) => {\n        globalThis.onmessage({ data })\n      })\n\n      Object.assign(globalThis, {\n        self: globalThis,\n        require,\n        Worker: nodeWorkerThreads.Worker,\n        importScripts: function (f) {\n          (0, eval)(require('fs').readFileSync(f, 'utf8') + '//# sourceURL=' + f)\n        },\n        postMessage: function (msg) {\n          parentPort.postMessage(msg)\n        }\n      })\n    }\n\n    main(_require, _init)\n  } else {\n    importScripts('./node_modules/@tybys/wasm-util/dist/wasm-util.js')\n    importScripts('./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js')\n\n    const nodeWasi = { WASI: globalThis.wasmUtil.WASI }\n    const _require = function (request) {\n      if (request === '@emnapi/wasi-threads') return globalThis.wasiThreads\n      if (request === 'node:wasi' || request === 'wasi') return nodeWasi\n      throw new Error('Can not find module: ' + request)\n    }\n    const _init = function () {}\n    main(_require, _init)\n  }\n})(function main (require, init) {\n  init()\n\n  const { WASI } = require('wasi')\n  const { ThreadMessageHandler, WASIThreads } = require('@emnapi/wasi-threads')\n\n  const handler = new ThreadMessageHandler({\n    async onLoad ({ wasmModule, wasmMemory }) {\n      const wasi = new WASI({\n        version: 'preview1'\n      })\n\n      const wasiThreads = new WASIThreads({\n        wasi,\n        childThread: true\n      })\n\n      const originalInstance = await WebAssembly.instantiate(wasmModule, {\n        env: {\n          memory: wasmMemory,\n        },\n        wasi_snapshot_preview1: wasi.wasiImport,\n        ...wasiThreads.getImportObject()\n      })\n\n      // must call `initialize` instead of `start` in child thread\n      const instance = wasiThreads.initialize(originalInstance, wasmModule, wasmMemory)\n\n      return { module: wasmModule, instance }\n    }\n  })\n\n  globalThis.onmessage = function (e) {\n    handler.handle(e)\n    // handle other messages\n  }\n})\n```\n","_attachments":{},"homepage":"https://github.com/toyobayashi/emnapi#readme","bugs":{"url":"https://github.com/toyobayashi/emnapi/issues"},"license":"MIT"}