Last active
January 27, 2016 08:25
-
-
Save Kikobeats/fcf63e33092b2fec26ec to your computer and use it in GitHub Desktop.
async stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 0 | |
function asyncFn (cb) { | |
setTimeout(function () { | |
console.log('emit new chunk') | |
return cb(null, {foo: 'bar'}) | |
}, 500) | |
} | |
module.exports = function () { | |
return from(function (size, next) { | |
if (count < 5) { | |
++count | |
asyncFn(function (err, chunk) { | |
next(null, chunk) | |
}) | |
} else { | |
next(null, null) | |
} | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emit new chunk | |
{ foo: 'bar' } | |
✖ undefined: stream.push() after EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now better using if else instead of while and return