bare-stow 0.1.6 → 0.1.7
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/lib/host.js +15 -3
- package/package.json +1 -1
package/lib/host.js
CHANGED
|
@@ -5,17 +5,29 @@ class IPC extends Protocol {
|
|
|
5
5
|
super(stream)
|
|
6
6
|
|
|
7
7
|
this._ready = new Promise((resolve, reject) => {
|
|
8
|
+
const cleanup = () => {
|
|
9
|
+
this.off('ready', onready).off('error', onerror).off('exit', onexit).off('close', onclose)
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
const onready = () => {
|
|
9
|
-
|
|
13
|
+
cleanup()
|
|
10
14
|
resolve()
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
const onerror = (err) => {
|
|
14
|
-
|
|
18
|
+
cleanup()
|
|
15
19
|
reject(err)
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
const onexit = (code) => {
|
|
23
|
+
// An error frame precedes the exit frame and is emitted on destroy
|
|
24
|
+
if (this.destroying) return
|
|
25
|
+
onerror(new Error(`Worker exited with code ${code} before ready`))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const onclose = () => onerror(new Error('Worker closed before ready'))
|
|
29
|
+
|
|
30
|
+
this.on('ready', onready).on('error', onerror).on('exit', onexit).on('close', onclose)
|
|
19
31
|
})
|
|
20
32
|
|
|
21
33
|
this._ready.catch(() => {})
|