StreamingBeta
Functions can stream a response so the first bytes reach the user before the work is finished. Streaming is on by default for every runtime.
export default {
fetch() {
const enc = new TextEncoder();
return new Response(new ReadableStream({
async start(c) {
for (const w of ['one', 'two', 'three']) {
c.enqueue(enc.encode(w + '\n'));
await new Promise((r) => setTimeout(r, 300));
}
c.close();
},
}));
},
};Was this helpful?