From 61796ae6e2350f4edf3f4808a5e7a948c35bffaa Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Fri, 20 Oct 2017 10:41:01 -0500 Subject: [PATCH] Sketch of a `finished` flag if you need it. --- base.js | 4 +++- writable.js | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/base.js b/base.js index 4514531..316fdb9 100644 --- a/base.js +++ b/base.js @@ -21,6 +21,8 @@ function Staccato (stream) { this.destroyed = false } +Staccato.CANCELLED = {} + Staccato.prototype._once = function (name, listener) { this._listeners[name] = listener this.stream.once(name, listener) @@ -31,7 +33,7 @@ Staccato.prototype._catch = function (error) { } Staccato.prototype.destroy = function () { - this._destroy([]) + this._destroy([ null, Staccato.CANCELLED ]) } Staccato.prototype._destroy = function (vargs) { diff --git a/writable.js b/writable.js index 48f1c84..2282808 100644 --- a/writable.js +++ b/writable.js @@ -20,6 +20,7 @@ var Staccato = require('./base') // function Writable (stream) { + this.finished = false Staccato.call(this, stream) } util.inherits(Writable, Staccato) @@ -41,6 +42,10 @@ Writable.prototype.write = cadence(function (async, buffer) { } }) +// Could have a `closed` property but if you cancel the `finish` with `destroy` +// it will not be set correctly. I'm not willing to leave a listener on the +// stream because destroy is supposed to remove itself from the stream. + // Wait for the underlying stream to finish. // @@ -49,7 +54,8 @@ Writable.prototype.close = cadence(function (async) { async(function () { this._delta = delta(async()).ee(this.stream).on('finish') this.stream.end() - }, function () { + }, function (cancelled) { + this.finished = cancelled !== Staccato.CANCELLED this._delta = null }) })