Created
March 29, 2013 20:57
-
-
Save anonymous/5273601 to your computer and use it in GitHub Desktop.
Node.js Readable example
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
// rs is a stream.Readable | |
rs.on('readable', function () { | |
while (true) { | |
var chunk = rs.read(); | |
if (chunk === null) break; | |
// do something with chunk | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd consider
while (true)
to be at least a red flag, if not an outright bug most of the time.This is somewhat clearer, imo:
Of course if your goal is just to pull data out asap, you may as well use
rs.on('data', function(chunk) { ... })
which basically does exactly that.