MCPcopy Create free account
hub / github.com/continuedev/continue / stopAfterMaxProcessingTime

Function stopAfterMaxProcessingTime

core/autocomplete/generation/utils.ts:1–27  ·  view source on GitHub ↗
(
  stream: AsyncGenerator<string>,
  maxTimeMs: number,
  fullStop: () => void,
)

Source from the content-addressed store, hash-verified

1export async function* stopAfterMaxProcessingTime(
2 stream: AsyncGenerator<string>,
3 maxTimeMs: number,
4 fullStop: () => void,
5): AsyncGenerator<string> {
6 const startTime = Date.now();
7 /**
8 * Check every 10 chunks to avoid performance overhead.
9 */
10 const checkInterval = 10;
11 let chunkCount = 0;
12 let totalCharCount = 0;
13
14 for await (const chunk of stream) {
15 yield chunk;
16
17 chunkCount++;
18 totalCharCount += chunk.length;
19
20 if (chunkCount % checkInterval === 0) {
21 if (Date.now() - startTime > maxTimeMs) {
22 fullStop();
23 return;
24 }
25 }
26 }
27}

Callers 2

utils.vitest.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected