Skip to content

Commit

Permalink
Sketch of a finished flag if you need it.
Browse files Browse the repository at this point in the history
  • Loading branch information
flatheadmill committed Oct 20, 2017
1 parent 9451334 commit 61796ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Staccato = require('./base')

//
function Writable (stream) {
this.finished = false
Staccato.call(this, stream)
}
util.inherits(Writable, Staccato)
Expand All @@ -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.

//
Expand All @@ -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
})
})
Expand Down

0 comments on commit 61796ae

Please sign in to comment.