Skip to content

Instantly share code, notes, and snippets.

@bmeck bmeck/wtf.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.