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

Function readStream

www/js/ext/eventsource.js:275–300  ·  view source on GitHub ↗
(stub, reader, ac)

Source from the content-addressed store, hash-verified

273 });
274 }
275 async function readStream(stub, reader, ac) {
276 stub.reader = reader;
277 var baseDelay = 500;
278 try {
279 for await (var msg of parseSSE(reader)) {
280 if (ac.signal.aborted) break;
281 if (msg.id) stub.lastEventId = msg.id;
282 if (msg.retry != null) baseDelay = msg.retry;
283 var eventType = msg.event || "message";
284 var evt = {
285 type: eventType,
286 data: msg.data,
287 lastEventId: msg.id || stub.lastEventId || ""
288 };
289 dispatch(stub, eventType, evt);
290 }
291 } catch (err) {
292 if (!ac.signal.aborted) {
293 dispatch(stub, "error", { type: "error", error: err });
294 }
295 }
296 stub.reader = null;
297 if (!stub.closed && !ac.signal.aborted) {
298 scheduleReconnect(stub, baseDelay);
299 }
300 }
301 function scheduleReconnect(stub, baseDelay) {
302 if (stub.closed) return;
303 baseDelay = baseDelay || 500;

Callers 1

startConnectionFunction · 0.70

Calls 3

parseSSEFunction · 0.70
dispatchFunction · 0.70
scheduleReconnectFunction · 0.70

Tested by

no test coverage detected