Skip to content

Instantly share code, notes, and snippets.

@L2L2L
Created September 8, 2014 02:03
Show Gist options
  • Save L2L2L/1b76d274adccb542159a to your computer and use it in GitHub Desktop.
Save L2L2L/1b76d274adccb542159a to your computer and use it in GitHub Desktop.
understanding the readable stream
var Readable;
Readable = require("stream").Readable;
var readable;
readable = new Readable();
var i;
i = 0;
readable._read = function(){
if(++i > 10){
return readable.push(null);//push null end the stream?
}
setTimeout(function(){
readable.push(i + "\n");
}, 1000);
};
//inner mechanism invoke the function untill... a centrain false value is pass through
readable.pipe(process.stdout);
//few questions:
/*\
|*| 1. does stream inherit from Array?
|*| 2. ... pretty much it for now...
|*| 3. <-- I like the comment style on the side so I'mma fill it out
|*| 4. one more to go.
|*| 5. done.
\*/
@aredridel
Copy link

  1. No.

@L2L2L
Copy link
Author

L2L2L commented Sep 8, 2014

okay thanks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment