Installations
npm install @broxus/await-semaphore
Score
71.5
Supply Chain
98.7
Quality
81.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Developer
notenoughneon
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
17.7.1
NPM Version
8.5.4
Statistics
63 Stars
18 Commits
18 Forks
5 Watching
1 Branches
2 Contributors
Updated on 20 Oct 2024
Bundle Size
1.71 kB
Minified
832.00 B
Minified + Gzipped
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
41,531
Last day
21.7%
129
Compared to previous day
Last week
13.2%
607
Compared to previous week
Last month
41.3%
2,794
Compared to previous month
Last year
-24.6%
14,423
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
5
await-semaphore
Awaitable semaphore/mutex
A semaphore implementation using ES6 promises and supporting 3 styles:
- async/await style (needs typescript)
- thunk style (automatic acquire/release)
- promise style
Also includes Mutex
as a convenience for new Semaphore(1)
.
API
new Semaphore(count: number)
Create a new semaphore with the given count.
1import {Semaphore} from 'await-semaphore'; 2 3var semaphore = new Semaphore(10);
semaphore.acquire(): Promise<() => void>
Acquire the semaphore and returns a promise for the release function. Be sure to handle release for exception case.
1semaphore.acquire() 2.then(release => { 3 //critical section... 4 doSomething() 5 .then(res => { 6 //... 7 release(); 8 }) 9 .catch(err => { 10 //... 11 release(); 12 }); 13});
semaphore.use(thunk: () => Promise): Promise
Alternate method for using the semaphore by providing a thunk. This automatically handles acquire/release.
1semaphore.use(() => { 2 //critical section... 3});
new Mutex()
An alias for new Semaphore(1)
. Mutex has the same methods as Semaphore.
1import {Mutex} from 'await-semaphore'; 2 3var mutex = new Mutex();
Examples
Create a version of fetch()
with concurrency limited to 10.
async/await style (typescript)
1var semaphore = new Semaphore(10); 2 3async function niceFetch(url) { 4 var release = await semaphore.acquire(); 5 var result = await fetch(url); 6 release(); 7 return result; 8}
thunk style (javascript)
1var semaphore = new Semaphore(10); 2 3function niceFetch(url) { 4 return semaphore.use(() => fetch(url)); 5}
promise style (javascript)
1var semaphore = new Semaphore(10); 2 3function niceFetch(url) { 4 return semaphore.acquire() 5 .then(release => { 6 return fetch(url) 7 .then(result => { 8 release(); 9 return result; 10 }); 11 }); 12}
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 2/15 approved changesets -- score normalized to 1
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
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
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-18
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 More