bare-tty 2.1.2 → 2.1.4

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 +16 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -15,6 +15,7 @@ exports.ReadStream = class TTYReadStream extends Readable {
15
15
  this._pendingDestroy = null
16
16
 
17
17
  this._reading = false
18
+ this._closing = false
18
19
  this._allowHalfOpen = allowHalfOpen
19
20
 
20
21
  this._buffer = Buffer.alloc(readBufferSize)
@@ -46,13 +47,15 @@ exports.ReadStream = class TTYReadStream extends Readable {
46
47
  }
47
48
 
48
49
  _predestroy () {
49
- if (this._handle === null) return
50
+ if (this._closing) return
51
+ this._closing = true
50
52
  binding.close(this._handle)
51
53
  TTYReadStream._streams.delete(this)
52
54
  }
53
55
 
54
56
  _destroy (cb) {
55
- if (this._handle === null) return cb(null)
57
+ if (this._closing) return cb(null)
58
+ this._closing = true
56
59
  this._pendingDestroy = cb
57
60
  binding.close(this._handle)
58
61
  TTYReadStream._streams.delete(this)
@@ -102,6 +105,8 @@ exports.WriteStream = class TTYWriteStream extends Writable {
102
105
  this._pendingFinal = null
103
106
  this._pendingDestroy = null
104
107
 
108
+ this._closing = false
109
+
105
110
  this._handle = binding.init(fd, empty, this,
106
111
  this._onwrite,
107
112
  this._onfinal,
@@ -130,7 +135,16 @@ exports.WriteStream = class TTYWriteStream extends Writable {
130
135
  binding.end(this._handle)
131
136
  }
132
137
 
138
+ _predestroy () {
139
+ if (this._closing) return
140
+ this._closing = true
141
+ binding.close(this._handle)
142
+ TTYWriteStream._streams.delete(this)
143
+ }
144
+
133
145
  _destroy (cb) {
146
+ if (this._closing) return cb(null)
147
+ this._closing = true
134
148
  this._pendingDestroy = cb
135
149
  binding.close(this._handle)
136
150
  TTYWriteStream._streams.delete(this)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-tty",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Native TTY streams for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [