1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| fetch( "", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({}) } ).then((res) => { const reader = res.body.getReader(); const decoder = new TextDecoder();
return reader.read().then(function processResult(result) { console.log(result); if (result.done) { return; }
const chunk = decoder.decode(result.value, { stream: true });
console.log(chunk);
return reader.read().then(processResult); }); }) .catch(error => { console.error('Error occurred while fetching event stream:', error); });
|