MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / nextWithTimeout

Function nextWithTimeout

packages/node/src/__tests__/tailSource.test.ts:8–27  ·  view source on GitHub ↗
(
  iterator: AsyncIterator<T>,
  timeoutMs = 2000,
)

Source from the content-addressed store, hash-verified

6import { READ_CHUNK_BYTES, createNodeTailSource } from "../streams/tail.js";
7
8async function nextWithTimeout<T>(
9 iterator: AsyncIterator<T>,
10 timeoutMs = 2000,
11): Promise<IteratorResult<T>> {
12 let timer: ReturnType<typeof setTimeout> | undefined;
13 try {
14 return await Promise.race([
15 iterator.next(),
16 new Promise<never>((_, reject) => {
17 timer = setTimeout(() => {
18 reject(new Error(`next() timed out after ${String(timeoutMs)}ms`));
19 }, timeoutMs);
20 }),
21 ]);
22 } finally {
23 if (timer !== undefined) {
24 clearTimeout(timer);
25 }
26 }
27}
28
29test("createNodeTailSource yields existing + appended lines when fromEnd=false", async () => {
30 const dir = await mkdtemp(join(tmpdir(), "rezi-tail-"));

Callers 1

tailSource.test.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected