Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created February 10, 2021 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jakearchibald/32b2155708a665e9c8e06642b7c09d86 to your computer and use it in GitHub Desktop.
Save jakearchibald/32b2155708a665e9c8e06642b7c09d86 to your computer and use it in GitHub Desktop.
async function mergeResponses(responsePromises) {
const headers = new Headers();
headers.append("Content-Type", "text/html");
const { readable, writable } = new TransformStream();
const response = new Response(readable, {
headers: { "Content-Type": "text/html" },
});
const done = (async function() {
for await (const response of responsePromises) {
await response.body.pipeTo(writable, { preventClose: true });
}
writable.getWriter().close();
})();
return { done, response };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment