Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ function StreamArray(list) {
StreamArray.prototype = Object.create(Readable.prototype, {constructor: {value: StreamArray}});

StreamArray.prototype._read = function(size) {
this.push(this._i < this._l ? this._list[this._i++] : null);
var self = this;
process.nextTick(function() {
self.push(self._i < self._l ? self._list[self._i++] : null);
});
};

module.exports = function(list) {
Expand Down
27 changes: 27 additions & 0 deletions test/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var test = require('tape')
, streamify = require('..')
, concat = require('concat-stream')
;

test('async, non-blocking', function(t) {
var s = streamify(['1', '2', '3']);

var i = 0;
s.on('data', function(item) {
i++;
});

process.nextTick(function() {
t.equal(0, i, 'should emit the first item after this code');
process.nextTick(function() {
t.equal(1, i, 'should emit the second item after this code');
process.nextTick(function() {
t.equal(2, i, 'should emit the third item after this code');
process.nextTick(function() {
t.equal(3, i, 'should have emitted all three items in the fourth tick');
t.end();
});
});
});
});
});