Skip to content

Instantly share code, notes, and snippets.

@samgiles
samgiles / async-streams-and-promises.js
Last active October 6, 2017 00:04
Returning a Stream in a Promise is an anti-pattern.
/** Method 1. Use a PassThrough stream */
var PassThrough = require('stream').PassThrough;
function myAsyncContent() {
var myContentStream = new PassThrough();
var streamPromise = getAsyncInfo().then(function(info) {
return createStreamFromInfo(info);
});