MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / task

Function task

src/pkg/utils/concurrency-control.test.ts:47–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45 let maxConcurrent = 0;
46
47 const task = async () => {
48 await sem.acquire();
49 concurrent++;
50 maxConcurrent = Math.max(maxConcurrent, concurrent);
51 // 模拟异步操作
52 await new Promise((r) => setTimeout(r, 10));
53 concurrent--;
54 sem.release();
55 };
56
57 await Promise.all(Array.from({ length: 10 }, () => task()));
58

Callers 1

Calls 2

acquireMethod · 0.80
releaseMethod · 0.80

Tested by

no test coverage detected