@farar/nodes
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -50,14 +50,7 @@ "use strict"; | ||
this._stream.once('error', (err) => { | ||
try { | ||
if (config_js_1.default.debug) { | ||
this._errorHandler(err); | ||
} | ||
if (this._stream instanceof node_stream_1.Readable) { | ||
this._stream.unpipe(); | ||
} | ||
if (config_js_1.default.debug && this._errorHandler) { | ||
this._errorHandler(err); | ||
} | ||
catch (err) { | ||
if (this._errorHandler && err instanceof Error) { | ||
this._errorHandler(err); | ||
} | ||
if (this._stream instanceof node_stream_1.Readable) { | ||
this._stream.unpipe(); | ||
} | ||
@@ -93,28 +86,18 @@ }); | ||
async _write(data, encoding) { | ||
if (!this._stream.closed && this._stream instanceof node_stream_1.Writable) { | ||
if (!this._stream.writableNeedDrain) { | ||
if (this._queue.length === 0) { | ||
if (this._stream.write(data, encoding ?? 'utf-8')) { | ||
return; | ||
} | ||
else { | ||
await (0, node_events_1.once)(this._stream, 'drain'); | ||
} | ||
} | ||
else { | ||
this._queue.push(data); | ||
this._size += !this._stream.writableObjectMode && (data instanceof Buffer || typeof data == 'string') ? data.length : 1; | ||
} | ||
while (this._queue.length) { | ||
const data = this._queue.shift(); | ||
this._size -= !this._stream.writableObjectMode && (data instanceof Buffer || typeof data == 'string') ? data.length : 1; | ||
if (!this._stream.write(data, encoding ?? 'utf-8')) { | ||
await (0, node_events_1.once)(this._stream, 'drain'); | ||
} | ||
} | ||
if (this._stream.closed || !(this._stream instanceof node_stream_1.Writable)) | ||
return; | ||
if (this._stream.writableNeedDrain) { | ||
this._queue.push(data); | ||
this._size += !this._stream.writableObjectMode && (data instanceof Buffer || typeof data == 'string') ? data.length : 1; | ||
return; | ||
} | ||
if (this._stream.write(data, encoding ?? 'utf-8')) | ||
return; | ||
await (0, node_events_1.once)(this._stream, 'drain'); | ||
while (this._queue.length) { | ||
const data = this._queue.shift(); | ||
this._size -= !this._stream.writableObjectMode && (data instanceof Buffer || typeof data == 'string') ? data.length : 1; | ||
if (!this._stream.write(data, encoding ?? 'utf-8')) { | ||
await (0, node_events_1.once)(this._stream, 'drain'); | ||
} | ||
else { | ||
this._queue.push(data); | ||
this._size += !this._stream.writableObjectMode && (data instanceof Buffer || typeof data == 'string') ? data.length : 1; | ||
} | ||
} | ||
@@ -121,0 +104,0 @@ } |
{ | ||
"name": "@farar/nodes", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -57,3 +57,3 @@ # Nodes | ||
- `options` `<NodeOptions>` | ||
- `errorHandler` `<(err: Error, ...params: Array<unknown>) => void>` An optional error handler that will be used in the event of an internal Error. | ||
- `errorHandler` `<(err: Error, ...params: Array<unknown>) => void>` An optional error handler that will be used in the event of an internal Error. **Default: `console.error`** | ||
@@ -60,0 +60,0 @@ _public_ **node.connect(...nodes)** |
53657
1063