We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6fd8fa commit 3e98f70Copy full SHA for 3e98f70
1 file changed
JavaScript/8-await-counting.js
@@ -1,7 +1,5 @@
1
'use strict';
2
3
-const fs = require('fs');
4
-
5
class CountingSemaphore {
6
constructor(concurrency) {
7
this.counter = concurrency;
@@ -31,6 +29,8 @@ class CountingSemaphore {
31
29
32
30
// Usage
33
+const semaphore = new CountingSemaphore(3);
+
34
const job = async (task) => {
35
console.log('try enter', task);
36
await semaphore.enter();
@@ -41,5 +41,4 @@ const job = async (task) => {
41
}, 1000);
42
};
43
44
-const semaphore = new CountingSemaphore(3);
45
for (let i = 0; i < 100; i++) job(i);
0 commit comments