Skip to content

Instantly share code, notes, and snippets.

@wanderview
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wanderview/16f2839ba57514a625c4 to your computer and use it in GitHub Desktop.
Save wanderview/16f2839ba57514a625c4 to your computer and use it in GitHub Desktop.
myStream.read(function handleChunk(chunk) {
if (!chunk) {
processDone();
return;
}
processChunk(chunk);
myStream.read(handleChunk);
});
myStream.read().then(function handleChunk(chunk) {
if (!chunk) {
return;
}
processChunk(chunk);
return myStream.read().then(handleChunk);
}).then(processDone);
@domenic
Copy link

domenic commented Apr 18, 2015

The following code (more similar to your callback code) would also not have this problem:

myStream.read().then(function handleChunk(chunk) {
  if (!chunk) {
    processDone();
    return;
  }
  processChunk(chunk);
  myStream.read().then(handleChunk);
});

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