bare-tty 2.1.3 → 2.1.5

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/binding.c +3 -11
  2. package/index.js +11 -4
  3. package/package.json +2 -2
package/binding.c CHANGED
@@ -243,13 +243,6 @@ bare_tty_init (js_env_t *env, js_callback_info_t *info) {
243
243
  return NULL;
244
244
  }
245
245
 
246
- err = uv_stream_set_blocking((uv_stream_t *) &tty->handle, true);
247
-
248
- if (err < 0) {
249
- js_throw_error(env, uv_err_name(err), uv_strerror(err));
250
- return NULL;
251
- }
252
-
253
246
  tty->env = env;
254
247
 
255
248
  err = js_get_typedarray_info(env, argv[1], NULL, (void **) &tty->read.base, &tty->read.len, NULL, NULL);
@@ -423,10 +416,9 @@ bare_tty_close (js_env_t *env, js_callback_info_t *info) {
423
416
 
424
417
  err = uv_tty_set_mode(&tty->handle, UV_TTY_MODE_NORMAL);
425
418
 
426
- if (err < 0) {
427
- js_throw_error(env, uv_err_name(err), uv_strerror(err));
428
- return NULL;
429
- }
419
+ // Resetting the mode won't always work, in particular on Windows when we
420
+ // close an output stream.
421
+ (void) err;
430
422
 
431
423
  uv_close((uv_handle_t *) &tty->handle, on_close);
432
424
 
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,
@@ -131,13 +136,15 @@ exports.WriteStream = class TTYWriteStream extends Writable {
131
136
  }
132
137
 
133
138
  _predestroy () {
134
- if (this._handle === null) return
139
+ if (this._closing) return
140
+ this._closing = true
135
141
  binding.close(this._handle)
136
142
  TTYWriteStream._streams.delete(this)
137
143
  }
138
144
 
139
145
  _destroy (cb) {
140
- if (this._handle === null) return cb(null)
146
+ if (this._closing) return cb(null)
147
+ this._closing = true
141
148
  this._pendingDestroy = cb
142
149
  binding.close(this._handle)
143
150
  TTYWriteStream._streams.delete(this)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-tty",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Native TTY streams for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/holepunchto/bare-tty.git"
18
+ "url": "git+https://github.com/holepunchto/bare-tty.git"
19
19
  },
20
20
  "author": "Holepunch",
21
21
  "license": "Apache-2.0",