Installations
npm install async-semaphore
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
0.12.0
NPM Version
2.5.1
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
17,896
Last day
0%
1
Compared to previous day
Last week
0%
4
Compared to previous week
Last month
0%
14
Compared to previous month
Last year
-84.2%
246
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
async-semaphore
A counting semaphore based on Java's Concurrent Semaphore.
Install
Install the module via npm:
npm install async-semaphore
Quick Example
1// fairness false 2 3var Semaphore = require('async-semaphore'); 4var semaphore = new Semaphore(0); 5 6semaphore.acquire(2, function() { 7 console.log('Hello'); 8}); 9 10semaphore.acquire(function() { 11 console.log('World'); 12 13 semaphore.release(2); 14}); 15 16setTimeout(function() { 17 semaphore.release(); 18}, 2000); 19 20// Output after 2 secs: World Hello 21
1// fairness true 2 3var Semaphore = require('async-semaphore'); 4var semaphore = new Semaphore(0, true); 5 6semaphore.acquire(2, function() { 7 console.log('Hello'); 8}); 9 10semaphore.acquire(function() { 11 console.log('World'); 12 13 semaphore.release(2); 14}); 15 16setTimeout(function() { 17 semaphore.release(); 18}, 2000); 19 20// No output after 2 secs because fairness is true. 21
Documentation
Constructor: Semaphore([permits
], [fairness
])
permits: Integer
Initial available permits of semaphore. Default: 0
.
fairness: Boolean
Fairness of semaphore. If set to true
, a FIFO rules applied, else, look on each acquirers permit value.
#availablePermits()
Returns the current number of permits available in this semaphore.
Returns: Integer
#acquire([permits
], handler
)
Acquires the given number of permits from this semaphore.
permits: Integer
The number of permits to acquire.
handler: Function
Handler function to call.
#getQueueAcquirers()
Returns an estimate of the number of acquirers waiting to acquire.
Returns: Function[]
#getQueueLength()
Returns an estimate of the number of acquirers waiting to acquire.
Returns: Integer
#release([permits
])
Releases the given number of permits, returning them to the semaphore.
permits: Integer
The number of permits to release.
#drainPermits()
Acquires and returns all permits that are immediately available.
Returns: Integer
#reducePermits(permits
)
Shrinks the number of available permits by the indicated reduction.
permits: Integer
The number of permits to remove.
#tryAcquire([permits
])
Acquires the given number of permits from this semaphore.
permits: Integer
The number of permits to acquire.
Returns: Boolean
true
if success, false
false if fail
License
The MIT License (MIT)
Copyright (c) 2014 Ian Mark Muninio
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/7 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to async-semaphore
async-sema
Semaphore using `async` and `await`
semaphore-async-await
A promise-based semaphore implementation suitable to be used with async/await.
@esfx/async-semaphore
Provides 'AsyncSemaphore', an async coordination primitive.
@esutils/async-semaphore
A minimal async semaphore library that implemented in `typescript`