Skip to content

Commit

Permalink
Implement interrupt.
Browse files Browse the repository at this point in the history
Closes #22.
  • Loading branch information
flatheadmill committed Jun 21, 2015
1 parent 67210cf commit acab288
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 8 additions & 0 deletions blocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ Blocker.prototype._consume = function () {
}
}

Blocker.prototype.interrupt = function (error) {
if (this._next) {
var callback = this._next.callback
delete this._next
callback(error)
}
}

module.exports = Blocker
1 change: 1 addition & 0 deletions release.ft
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### Issue by Issue

* Implement interrupt. #22.
* Update license for 2015. #20.
16 changes: 11 additions & 5 deletions t/blocker/block.t.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('proof')(2, prove)
require('proof')(3, prove)

function prove (equal) {
function prove (assert) {
var Blocker = require('../..')
var stream = require('stream')
var pipe = new stream.PassThrough
Expand All @@ -12,9 +12,15 @@ function prove (equal) {
pipe.write(buffer.slice(0, 1))

blocker.block(2, function (error, buffer) {
equal(buffer.length, 2, 'sliced')
equal(buffer.readUInt16BE(0), 0xaaaa, 'block is ready')
assert(buffer.length, 2, 'sliced')
assert(buffer.readUInt16BE(0), 0xaaaa, 'block is ready')
})

pipe.write(buffer.slice(1))

blocker.interrupt(new Error)

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

0 comments on commit acab288

Please sign in to comment.