()
| 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 |
no test coverage detected