Skip to content

Instantly share code, notes, and snippets.

@bmeck
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmeck/d059b936c716b51b4801 to your computer and use it in GitHub Desktop.
Save bmeck/d059b936c716b51b4801 to your computer and use it in GitHub Desktop.
readable yet not...
// something about delaying a pipe causes child process stdout to become `readable:false`
function test(prefix, delay_fn, cb) {
var x=new (require("stream").Transform);
x._transform = (function (chunk, enc, cb) {
console.log(prefix, 'chunk:', chunk);
cb(null);
})
var child=require("child_process").spawn("head", ["-c","-2"]);
child.on('exit', function () {
console.log('exit', prefix);
if (cb) cb();
})
child.stdout.on('readable', console.log.bind(console, prefix, 'emitted readable'))
delay_fn(function () {
console.log(prefix, 'set to pipe(), is readable = ', child.stdout.readable)
child.stdout.pipe(x)
})
}
test('setTimeout (100)', function (fn) {
setTimeout(fn, 100);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment