Last active
August 29, 2015 14:09
-
-
Save bmeck/d059b936c716b51b4801 to your computer and use it in GitHub Desktop.
readable yet not...
This file contains 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
// 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