Fetch Stream

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 Oct 8 7:16
Editor
Edited
Edited
2021 Oct 8 8:35
Refs
Refs

fetch stream

async function* streamAsyncIterator(stream) { const reader = stream.getReader() try { while (true) { const { done, value } = await reader.read() if (done) return yield value } } finally { reader.releaseLock() } } const res = await fetch(url, { method: 'POST', headers: { Accept: "application/json", 'Content-Type': 'application/json' }, body: JSON.stringify({}) }) for await (const item of streamAsyncIterator(res.body)) datas.push(item)

Recommendations