diff options
Diffstat (limited to 'src/js/node/stream.js')
-rw-r--r-- | src/js/node/stream.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/js/node/stream.js b/src/js/node/stream.js index 75b879a3d..4a54c04a7 100644 --- a/src/js/node/stream.js +++ b/src/js/node/stream.js @@ -5497,7 +5497,11 @@ var NativeWritable = class NativeWritable extends Writable { #internalConstruct(cb) { this._writableState.constructed = true; this.constructed = true; - cb(); + if (typeof cb === "function") cb(); + process.nextTick(() => { + this.emit("open", this.fd); + this.emit("ready"); + }); } #lazyConstruct() { @@ -5548,8 +5552,23 @@ var NativeWritable = class NativeWritable extends Writable { } #internalDestroy(error, cb) { - this._writableState.destroyed = true; - if (cb) cb(error); + const w = this._writableState; + const r = this._readableState; + + if (w) { + w.destroyed = true; + w.closeEmitted = true; + } + if (r) { + r.destroyed = true; + r.closeEmitted = true; + } + + if (typeof cb === "function") cb(error); + + if (w?.closeEmitted || r?.closeEmitted) { + this.emit("close"); + } } #internalFinal(cb) { |