bare-worker 3.0.1 → 3.1.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.
Files changed (2) hide show
  1. package/index.js +13 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -22,12 +22,22 @@ module.exports = exports = class Worker extends MessagePort {
22
22
  })
23
23
 
24
24
  this._exitCode = 0
25
+ this._terminating = null
25
26
 
26
27
  this.on('close', this._onexit).start()
27
28
  }
28
29
 
29
30
  terminate() {
31
+ if (this._terminating !== null) return this._terminating.promise
32
+
33
+ if (this._state & constants.state.CLOSED) {
34
+ return Promise.resolve(this._exitCode)
35
+ }
36
+
37
+ this._terminating = Promise.withResolvers()
30
38
  this._terminate()
39
+
40
+ return this._terminating.promise
31
41
  }
32
42
 
33
43
  [Symbol.for('bare.inspect')]() {
@@ -40,6 +50,9 @@ module.exports = exports = class Worker extends MessagePort {
40
50
 
41
51
  _onexit() {
42
52
  this._thread.join()
53
+
54
+ if (this._terminating !== null) this._terminating.resolve(this._exitCode)
55
+
43
56
  this.emit('exit', this._exitCode)
44
57
  }
45
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-worker",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "Higher-level worker threads for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",