INNER CODE UNIT · TypeScript
toAsyncIterable
enisdenjo/graphql-sse · src/client.ts:934
for await (const chunk of toAsyncIterable(res.body!)) {
if (typeof chunk === 'string')
throw (error = new Error(`Unexpected string chunk "${chunk}"`)); // set error as fatal indicator
// read chunk and if messages are ready, yield them
let msgs;
try {
msgs = parse(chunk);
} catch (err) {
throw (error = err); // set error as fatal indicator
}
if (!msgs) continue;
for (const msg of msgs) {
try {
onMessage?.(msg);
} catch (err) {
throw (error = err); // set error as fatal indicator