Skip to content

Instantly share code, notes, and snippets.

@joliss
Last active December 17, 2015 14:09
Show Gist options
  • Save joliss/5622783 to your computer and use it in GitHub Desktop.
Save joliss/5622783 to your computer and use it in GitHub Desktop.
var through = require('through')
getSomeStream(function(err, stream) {
stream.pause() // pause until we are ready to attach handlers
process.nextTick(function() { // could be setTimeout
stream.pipe(process.stdout) // now we're ready to consume the stream...
stream.resume()
})
})
function getSomeStream(callback) {
var someStream = through().pause()
someStream.write('foo\n')
someStream.end()
callback(null, someStream)
// Whoops, this resumes *after* the pause above, so all our data gets swallowed now:
someStream.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment