Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@node-libraries/semaphore
Advanced tools
Implement virtual semaphore for asynchronous processing
Implement virtual semaphore for asynchronous processing
// Importing packages
import { semaphore } from "@node-libraries/semaphore";
// Instance Creation
const s = semaphore();
// Synchronization Lock
await s.acquire();
// Synchronization lock release
s.release();
// Wait until all locks are unlocked.
await s.all();
// Specify maximum number of parallels
const s = semaphore(5);
import { semaphore } from "@node-libraries/semaphore";
const f = (value: string) =>
new Promise<void>((resolve) => {
console.timeLog("debug", value);
setTimeout(resolve, 1000);
});
const main = async () => {
console.time("debug");
const s = semaphore();
["A", "B", "C", "D", "E"].forEach(async (v) => {
await s.acquire();
await f(v);
s.release();
});
await s.all(); // Wait for everything to be finished.
console.timeLog("debug", "end");
};
main();
/* Result
debug: 0.197ms A
debug: 1.014s B
debug: 2.027s C
debug: 3.039s D
debug: 4.040s E
debug: 5.050s end
*/
import { semaphore } from "@node-libraries/semaphore";
const f = (value: string) =>
new Promise<void>((resolve) => {
console.timeLog("debug", value);
setTimeout(resolve, 1000);
});
const main = async () => {
console.time("debug");
const s = semaphore(2);
["A", "B", "C", "D", "E"].forEach(async (v) => {
await s.acquire();
await f(v);
s.release();
});
await s.all(); // Wait for everything to be finished.
console.timeLog("debug", "end");
};
main();
/* Result
debug: 0.19ms A
debug: 1.826ms B
debug: 1.005s C
debug: 1.005s D
debug: 2.012s E
debug: 3.028s end
*/
FAQs
Implement virtual semaphore for asynchronous processing
The npm package @node-libraries/semaphore receives a total of 134 weekly downloads. As such, @node-libraries/semaphore popularity was classified as not popular.
We found that @node-libraries/semaphore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.