Skip to content

Commit

Permalink
Forward interrupt set before a block.
Browse files Browse the repository at this point in the history
  • Loading branch information
flatheadmill committed Jun 23, 2015
1 parent 7d7d4e2 commit 43be6ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 10 additions & 2 deletions blocker.js
Expand Up @@ -10,8 +10,14 @@ util.inherits(Blocker, Transform)

Blocker.prototype.block = function (size, callback) {
ok(!this._next, 'size already set')
this._next = { size: size, callback: callback }
this._consume()
if (this._error) {
var error = this._error
delete this._error
callback(error)
} else {
this._next = { size: size, callback: callback }
this._consume()
}
}

Blocker.prototype._read = function () {
Expand All @@ -37,6 +43,8 @@ Blocker.prototype.interrupt = function (error) {
var callback = this._next.callback
delete this._next
callback(error)
} else {
this._error = error
}
}

Expand Down
8 changes: 6 additions & 2 deletions t/blocker/block.t.js
@@ -1,4 +1,4 @@
require('proof')(3, prove)
require('proof')(4, prove)

function prove (assert) {
var Blocker = require('../..')
Expand All @@ -17,7 +17,11 @@ function prove (assert) {
})
pipe.write(buffer.slice(1))

blocker.interrupt(new Error)
blocker.interrupt(new Error('interrupt'))

blocker.block(16, function (error) {
assert(error.message, 'interrupt', 'interrupt')
})

blocker.block(16, function (error) {
assert(error.message, 'interrupt', 'interrupt')
Expand Down

0 comments on commit 43be6ef

Please sign in to comment.