Skip to content

Instantly share code, notes, and snippets.

@jakearchibald

jakearchibald/1.js Secret

Created Feb 10, 2021
Embed
What would you like to do?
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