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

Function readStream

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

Source from the content-addressed store, hash-verified

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