Skip to content

Instantly share code, notes, and snippets.

@kriszyp
Created January 28, 2010 23:33
Show Gist options
  • Save kriszyp/289272 to your computer and use it in GitHub Desktop.
Save kriszyp/289272 to your computer and use it in GitHub Desktop.
return [200, headers:{}, body:{
forEach: function(write){
var promise = new Promise;
someEventEmitter.addListener("data", function(data){
write(data);
}
someEventEmitter.addListener("complete", function(){
promise.resolve();
}
return promise;
}
};
// or an example of leveraging promise chaining
return [200, headers:{}, body:{
forEach: function(write){
return someLazyAsyncArray.forEach(function(item){
write(JSON.stringify(item));
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment