MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / worker

Function worker

src/shared/pub/utils.ts:40–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38
39 /// A worker that continuously processes items until there are none left.
40 const worker = async () => {
41 while (!firstError && !cancellationToken.isCancellationRequested) {
42 // Grab the index of the next item.
43 const index = nextIndex++;
44 if (index >= items.length)
45 return; // All items are done.
46
47 const item = items[index];
48 onStarted?.(item); // Signal that we're starting.
49
50 try {
51 await task(item); // Run the main task.
52 completed++;
53 onCompleted?.(completed, items.length, item); // Signal that we're done.
54 } catch (error) {
55 firstError ??= error;
56 return;
57 }
58 }
59 };
60
61 await Promise.all(Array.from({ length: maxWorkers }, () => worker()));
62

Callers 1

runWithConcurrencyLimitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected