bufferedstream
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -88,3 +88,2 @@ var util = require('util'); | ||
this.paused = true; | ||
this.emit('pause'); | ||
} | ||
@@ -99,3 +98,2 @@ }; | ||
this.paused = false; | ||
this.emit('resume'); | ||
flushOnNextTick(this); | ||
@@ -177,2 +175,4 @@ } | ||
function flush(stream) { | ||
if (!stream._buffer) return; | ||
var chunk; | ||
@@ -179,0 +179,0 @@ while (stream._buffer.length) { |
@@ -5,3 +5,3 @@ { | ||
"description": "A base stream class for node that reliably buffers until next tick", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -57,66 +57,25 @@ var assert = require('assert'); | ||
describe('', function () { | ||
var stream, pauseCount, resumeCount; | ||
describe('that is paused', function () { | ||
var stream; | ||
beforeEach(function () { | ||
stream = new BufferedStream; | ||
pauseCount = 0; | ||
resumeCount = 0; | ||
stream.on('pause', function () { | ||
pauseCount += 1; | ||
}); | ||
stream.on('resume', function () { | ||
resumeCount += 1; | ||
}); | ||
stream.pause(); | ||
}); | ||
describe('that is not paused', function () { | ||
it('does not emit resume when resumed', function () { | ||
assert.equal(resumeCount, 0); | ||
stream.resume(); | ||
assert.equal(resumeCount, 0); | ||
it('only emits "end" after it is resumed', function (done) { | ||
var endWasCalled = false; | ||
stream.on('end', function () { | ||
endWasCalled = true; | ||
}); | ||
it('emits pause when paused', function () { | ||
assert.equal(pauseCount, 0); | ||
stream.pause(); | ||
assert.equal(pauseCount, 1); | ||
}); | ||
}); | ||
stream.end(); | ||
assert.equal(endWasCalled, false); | ||
describe('that is paused', function () { | ||
beforeEach(function () { | ||
stream.pause(); | ||
}); | ||
it('does not emit pause when paused again', function () { | ||
assert.equal(pauseCount, 1); | ||
stream.pause(); | ||
assert.equal(pauseCount, 1); | ||
}); | ||
it('emits resume when resumed', function () { | ||
assert.equal(resumeCount, 0); | ||
setTimeout(function () { | ||
stream.resume(); | ||
assert.equal(resumeCount, 1); | ||
}); | ||
it('only emits "end" after it is resumed', function (done) { | ||
var endWasCalled = false; | ||
stream.on('end', function () { | ||
endWasCalled = true; | ||
}); | ||
stream.end(); | ||
assert.equal(endWasCalled, false); | ||
setTimeout(function () { | ||
stream.resume(); | ||
setTimeout(function () { | ||
assert.equal(endWasCalled, true); | ||
done(); | ||
}, 1); | ||
assert.equal(endWasCalled, true); | ||
done(); | ||
}, 1); | ||
}); | ||
}, 1); | ||
}); | ||
@@ -123,0 +82,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17075
417