@napi-rs/image-wasm32-wasi 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createOnMessage as __wasmCreateOnMessageForFsProxy,
3
3
  getDefaultContext as __emnapiGetDefaultContext,
4
- instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
4
+ instantiateNapiModule as __emnapiInstantiateNapiModule,
5
5
  WASI as __WASI,
6
6
  } from '@napi-rs/wasm-runtime'
7
7
 
@@ -25,7 +25,7 @@ const {
25
25
  instance: __napiInstance,
26
26
  module: __wasiModule,
27
27
  napiModule: __napiModule,
28
- } = __emnapiInstantiateNapiModuleSync(__wasmFile, {
28
+ } = await __emnapiInstantiateNapiModule(__wasmFile, {
29
29
  context: __emnapiContext,
30
30
  asyncWorkPoolSize: 4,
31
31
  wasi: __wasi,
package/image.wasi.cjs CHANGED
@@ -65,6 +65,29 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
65
65
  worker.onmessage = ({ data }) => {
66
66
  __wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67
67
  }
68
+
69
+ // The main thread of Node.js waits for all the active handles before exiting.
70
+ // But Rust threads are never waited without `thread::join`.
71
+ // So here we hack the code of Node.js to prevent the workers from being referenced (active).
72
+ // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
73
+ // a worker is consist of two handles: kPublicPort and kHandle.
74
+ {
75
+ const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
76
+ s.toString().includes("kPublicPort")
77
+ );
78
+ if (kPublicPort) {
79
+ worker[kPublicPort].ref = () => {};
80
+ }
81
+
82
+ const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
83
+ s.toString().includes("kHandle")
84
+ );
85
+ if (kPublicPort) {
86
+ worker[kHandle].ref = () => {};
87
+ }
88
+
89
+ worker.unref();
90
+ }
68
91
  return worker
69
92
  },
70
93
  overwriteImports(importObject) {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/image-wasm32-wasi",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "cpu": [
5
5
  "wasm32"
6
6
  ],