MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / replayStream

Function replayStream

demo/chat/stream-replay.ts:34–50  ·  view source on GitHub ↗
(
  text: string,
  onChunk: (chunk: string) => void,
  options: ReplayOptions,
)

Source from the content-addressed store, hash-verified

32
33/** Replay saved HTML text chunk-by-chunk like a live API stream. */
34export async function replayStream(
35 text: string,
36 onChunk: (chunk: string) => void,
37 options: ReplayOptions,
38): Promise<void> {
39 let index = 0;
40 while (index < text.length) {
41 if (options.signal?.aborted) {
42 throw new DOMException("Aborted", "AbortError");
43 }
44 const size = nextChunkSize(text, index, options.chunkSize);
45 const chunk = text.slice(index, index + size);
46 index += size;
47 onChunk(chunk);
48 await sleep(options.delayMs, options.signal);
49 }
50}

Callers 1

ChatAppFunction · 0.90

Calls 2

nextChunkSizeFunction · 0.85
sleepFunction · 0.85

Tested by

no test coverage detected