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

Function sleep

demo/chat/stream-replay.ts:9–24  ·  view source on GitHub ↗
(ms: number, signal?: AbortSignal)

Source from the content-addressed store, hash-verified

7}
8
9function sleep(ms: number, signal?: AbortSignal): Promise<void> {
10 if (ms <= 0) {
11 return Promise.resolve();
12 }
13 return new Promise((resolve, reject) => {
14 const timer = window.setTimeout(resolve, ms);
15 signal?.addEventListener(
16 "abort",
17 () => {
18 window.clearTimeout(timer);
19 reject(new DOMException("Aborted", "AbortError"));
20 },
21 { once: true },
22 );
23 });
24}
25
26function nextChunkSize(text: string, index: number, chunkSize: number): number {
27 if (chunkSize > 0) {

Callers 1

replayStreamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected