Created
September 8, 2014 02:03
-
-
Save L2L2L/1b76d274adccb542159a to your computer and use it in GitHub Desktop.
understanding the readable stream
This file contains hidden or 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
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. | |
\*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment