bare-worker 3.0.0 → 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.
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- /* global Bare */
2
1
  const Channel = require('bare-channel')
3
2
  const MessageChannel = require('./lib/message-channel')
4
3
  const MessagePort = require('./lib/message-port')
@@ -17,17 +16,28 @@ module.exports = exports = class Worker extends MessagePort {
17
16
  data: {
18
17
  channel: channel.handle,
19
18
  filename,
20
- data: opts.workerData
19
+ data: opts.workerData,
20
+ imports: module.imports
21
21
  }
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
  }
@@ -1,4 +1,3 @@
1
- /* global Bare */
2
1
  const EventEmitter = require('bare-events')
3
2
  const Channel = require('bare-channel')
4
3
  const constants = require('./constants')
@@ -1,4 +1,3 @@
1
- /* global Bare */
2
1
  const Channel = require('bare-channel')
3
2
  const Module = require('bare-module')
4
3
  const os = require('bare-os')
@@ -7,7 +6,7 @@ const MessagePort = require('./message-port')
7
6
  const worker = require('..')
8
7
  const { Thread } = Bare
9
8
 
10
- const { channel: handle, filename, data } = Thread.self.data
9
+ const { channel: handle, filename, data, imports } = Thread.self.data
11
10
 
12
11
  const channel = Channel.from(handle, { interfaces: [MessagePort] })
13
12
 
@@ -21,7 +20,12 @@ worker.parentPort._online()
21
20
 
22
21
  worker.workerData = data
23
22
 
24
- Module.load(Module.resolve(filename, url.pathToFileURL(os.cwd() + '/')))
23
+ Module.load(
24
+ Module.resolve(filename, url.pathToFileURL(os.cwd() + '/'), {
25
+ imports
26
+ }),
27
+ { imports }
28
+ )
25
29
 
26
30
  function onnewlistener(name, fn) {
27
31
  if (fn === onremovelistener || fn === onerror) return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-worker",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Higher-level worker threads for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "homepage": "https://github.com/holepunchto/bare-worker#readme",
30
30
  "dependencies": {
31
- "bare-channel": "^5.0.1",
31
+ "bare-channel": "^5.0.5",
32
32
  "bare-events": "^2.2.1",
33
- "bare-module": "^4.0.0",
33
+ "bare-module": "^5.0.0",
34
34
  "bare-os": "^3.0.1",
35
35
  "bare-url": "^2.0.1"
36
36
  },