MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / readStream

Function readStream

src/ext/eventsource.js:282–313  ·  view source on GitHub ↗
(stub, reader, ac)

Source from the content-addressed store, hash-verified

280}
281
282async function readStream(stub, reader, ac) {
283 stub.reader = reader;
284 var baseDelay = 500;
285
286 try {
287 for await (var msg of parseSSE(reader)) {
288 if (ac.signal.aborted) break;
289
290 if (msg.id) stub.lastEventId = msg.id;
291 if (msg.retry != null) baseDelay = msg.retry;
292
293 var eventType = msg.event || 'message';
294 var evt = {
295 type: eventType,
296 data: msg.data,
297 lastEventId: msg.id || stub.lastEventId || '',
298 };
299 dispatch(stub, eventType, evt);
300 }
301 } catch (err) {
302 if (!ac.signal.aborted) {
303 dispatch(stub, 'error', { type: 'error', error: err });
304 }
305 }
306
307 stub.reader = null;
308
309 // Stream ended - reconnect unless explicitly closed
310 if (!stub.closed && !ac.signal.aborted) {
311 scheduleReconnect(stub, baseDelay);
312 }
313}
314
315function scheduleReconnect(stub, baseDelay) {
316 if (stub.closed) return;

Callers 1

startConnectionFunction · 0.70

Calls 3

parseSSEFunction · 0.70
dispatchFunction · 0.70
scheduleReconnectFunction · 0.70

Tested by

no test coverage detected