bare-ipc 1.1.0 → 1.1.1

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 (3) hide show
  1. package/README.md +47 -0
  2. package/index.js +9 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,6 +6,53 @@ Lightweight pipe-based IPC for Bare.
6
6
  npm i bare-ipc
7
7
  ```
8
8
 
9
+ ## API
10
+
11
+ ### `IPC`
12
+
13
+ #### `const [portA, portB] = IPC.open(opts)`
14
+
15
+ Returns a pair of `IPCPort`s for use constructing the IPC duplex stream based on
16
+ `bare-pipe`.
17
+
18
+ #### `const ipc = new IPC(port)`
19
+
20
+ Returns a duplex stream using the provided port. See `streamx`'s [`Duplex`](https://github.com/mafintosh/streamx?tab=readme-ov-file#duplex-stream) for Duplex API.
21
+
22
+ #### `ipc.ref()`
23
+
24
+ Increase the reference count for the IPC to keep the event loop alive.
25
+
26
+ A common pattern is to `ipc.ref()` on `Bare.on('resume')` and `ipc.unref()` on
27
+ suspend like so:
28
+
29
+ ```js
30
+ Bare.on('suspend', () => ipc.unref()).on('resume', () => ipc.ref())
31
+ ```
32
+
33
+ #### `ipc.unref()`
34
+
35
+ Decrease the reference count for the IPC to allow the event loop to exit.
36
+
37
+ See [`ipc.ref()`](#ipcref) for common pattern to keep the event loop alive.
38
+
39
+ ### `IPCPort`
40
+
41
+ #### `const port = new IPCPort(incoming, outgoing)`
42
+
43
+ The arguments are:
44
+
45
+ - `incoming` is the read file handle
46
+ - `outgoing` is the write file handle
47
+
48
+ #### `port.connect()`
49
+
50
+ Returns an `IPC` connected to the `port`.
51
+
52
+ #### `port.detached`
53
+
54
+ A boolean for whether the `port` is detached.
55
+
9
56
  ## License
10
57
 
11
58
  Apache-2.0
package/index.js CHANGED
@@ -45,6 +45,11 @@ module.exports = exports = class IPC extends Duplex {
45
45
  cb(null)
46
46
  }
47
47
 
48
+ _predestroy() {
49
+ this._incoming.destroy()
50
+ this._outgoing.destroy()
51
+ }
52
+
48
53
  _ondata(data) {
49
54
  if (this.push(data) === false) {
50
55
  this._incoming.pause()
@@ -95,9 +100,9 @@ class IPCPort {
95
100
  }
96
101
  }
97
102
 
98
- exports.open = function open(opts) {
99
- const a = Pipe.pipe(opts)
100
- const b = Pipe.pipe(opts)
103
+ exports.open = function open() {
104
+ const a = Pipe.pipe()
105
+ const b = Pipe.pipe()
101
106
 
102
- return [new IPCPort(a[0], b[1], opts), new IPCPort(b[0], a[1], opts)]
107
+ return [new IPCPort(a[0], b[1]), new IPCPort(b[0], a[1])]
103
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ipc",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Lightweight pipe-based IPC for Bare",
5
5
  "exports": {
6
6
  ".": {