Skip to content

Commit

Permalink
Report last error when invoked while destroyed.
Browse files Browse the repository at this point in the history
  • Loading branch information
flatheadmill committed Jun 19, 2017
1 parent dd6a2a9 commit 3ede45b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ var cadence = require('cadence')
var delta = require('delta')
var Destructible = require('destructible')
var interrupt = require('interrupt').createInterrupter('staccato')
var coalesce = require('extant')

function Staccato (stream, opening) {
this.stream = stream
this._destructible = new Destructible('staccato')
this._listeners = {
open: this._open.bind(this),
error: this.destroy.bind(this)
error: this._destructible.destroy.bind(this._destructible)
}
this._destructible.markDestroyed(this)
this._delta = null
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{
"cadence": "1.0.x",
"delta": "1.2.0",
"extant": "1.0.x",
"interrupt": "5.0.x",
"destructible": "0.13.x"
},
Expand Down
2 changes: 2 additions & 0 deletions readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Readable.prototype.read = cadence(function (async) {
this._destructible.invokeDestructor('delta')
}
if (this.destroyed) {
// TODO Maybe we raise an exception if there is an error using
// an Interrupt based assert.
// TODO Unlike Writable, reading a closed Readable will always
// return null no matter how often you call it.
this._readable = true
Expand Down
6 changes: 4 additions & 2 deletions writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ var cadence = require('cadence')
var delta = require('delta')
var Staccato = require('./base')
var interrupt = require('interrupt').createInterrupter('staccato')
var coalesce = require('extant')

function Writable (stream, opening) {
Staccato.call(this, stream, opening)
}
util.inherits(Writable, Staccato)

Writable.prototype.write = cadence(function (async, buffer) {
interrupt.assert(!this.destroyed, 'destroyed')
interrupt.assert(!this.destroyed, 'destroyed', coalesce(this._destructible.errors[0]))
if (!this.stream.write(buffer)) { // <- does this 'error' if `true`?
interrupt.assert(!this.destroyed, 'destroyed', coalesce(this._destructible.errors[0]))
async(function () {
this._destructible.invokeDestructor('error')
this._destructible.addDestructor('delta', this, '_cancel')
Expand All @@ -27,7 +29,7 @@ Writable.prototype.write = cadence(function (async, buffer) {
})

Writable.prototype.close = cadence(function (async) {
interrupt.assert(!this.destroyed, 'destroyed')
interrupt.assert(!this.destroyed, 'destroyed', coalesce(this._destructible.errors[0]))
async(function () {
this._destructible.invokeDestructor('error')
this._destructible.addDestructor('delta', this, '_cancel')
Expand Down

0 comments on commit 3ede45b

Please sign in to comment.