
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
semaphore_with_arguments
Advanced tools
Install: npm install semaphore_with_arguments
Limit simultaneous access to a resource.
// Create
var sem = require('semaphore')(capacity);
// Take
sem.take(fn[, n=1])
sem.take(n, fn)
// Leave
sem.leave([n])
// Limit concurrent db access
var sem = require('semaphore')(1);
var server = require('http').createServer(req, res) {
sem.take(function() {
expensive_database_operation(function(err, res) {
sem.leave();
if (err) return res.end("Error");
return res.end(res);
});
});
});
// 2 clients at a time
var sem = require('semaphore')(2);
var server = require('http').createServer(req, res) {
res.write("Then good day, madam!");
sem.take(function() {
res.end("We hope to see you soon for tea.");
sem.leave();
});
});
// Rate limit
var sem = require('semaphore')(10);
var server = require('http').createServer(req, res) {
sem.take(function() {
res.end(".");
setTimeout(sem.leave, 500)
});
});
// Pass arguments
var sem = require('semaphore')(10);
var server = require('http').createServer(req, res) {
var passMe = "String to pass";
sem.take({ aFabulousString: passMe }, function(args) {
res.end(".");
console.log(args.aFabulousString); // will ouput "String to pass"
setTimeout(sem.leave, 500)
});
});
MIT
FAQs
semaphore.js with some more featues
The npm package semaphore_with_arguments receives a total of 1 weekly downloads. As such, semaphore_with_arguments popularity was classified as not popular.
We found that semaphore_with_arguments 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.