stream = fs.createReadStream(inFile);
result = stream.read();
function _main() {
result = stream.read();
}
setTimeout(_main, delay);
If I read in a call-back on the readable
event, read succeeds but a second readable
event is emitted
stream.on('readable', () => {
result = stream.read()
});
function main(repeats) {
console.log(`\n${ESC}${BOLD};${RED}m${stamp()}starting main: ${repeats}${ESC}m`);
// connect a readstream to the same file
stream = specs.Stream();
// try to read it
if(options.immediate)
logit(`immediate`, 0); // null
if(options.timer)
logit(`after timeout`, options.timer); // success, no more readable events
if(!options["not-on-readable"])
stream.on('readable', (() => {
console.log(`${stamp()}setting listener on readable`)
var count = 0;
return () => {
logit(`after readable:\t${++count}`, 0);
if(repeats)
stream.on('close', main.bind(this, --repeats))
}
})()); // success, but a second readable event is emitted
else
main.bind(this, --repeats);
console.log(`${ESC}${BOLD};${RED}m${stamp()}ending main: ${repeats}${ESC}m\n`);
}
main(options.repeats);