Gathering detailed insights and metrics for p-fifo
Gathering detailed insights and metrics for p-fifo
Gathering detailed insights and metrics for p-fifo
Gathering detailed insights and metrics for p-fifo
🚦 Promised First-In-First-Out buffer. Await on push to be told when a value is consumed and await on shift for a value to consume when the buffer is empty.
npm install p-fifo
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
14 Commits
1 Forks
2 Watching
6 Branches
1 Contributors
Updated on 23 Nov 2021
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
9.5%
13,771
Compared to previous day
Last week
18.2%
72,364
Compared to previous week
Last month
-5%
287,479
Compared to previous month
Last year
-4.4%
3,742,088
Compared to previous year
Promised First-In-First-Out buffer. Await on push to be told when a value is consumed and await on shift for a value to consume when the buffer is empty
1npm i p-fifo
await
on push to be told when your pushed value is consumed:
1const Fifo = require('p-fifo') 2const fifo = new Fifo() 3 4// Consume a value from the buffer after 1 second 5setTimeout(() => fifo.shift(), 1000) 6 7console.time('push') 8// Nothing in the buffer, push a value and wait for it to be consumed 9await fifo.push('hello') 10console.log('"hello" was consumed') 11console.timeEnd('push') 12 13// Output: 14// "hello" was consumed 15// push: 1006.723ms
If the buffer is empty, you can await
on a value to be pushed:
1const Fifo = require('p-fifo') 2const fifo = new Fifo() 3 4// Push a value into the buffer after 1 second 5setTimeout(() => fifo.push('hello'), 1000) 6 7console.time('shift') 8// Nothing in the buffer, wait for something to arrive 9const value = await fifo.shift() 10console.log(`consumed "${value}" from the buffer`) 11console.timeEnd('shift') 12 13// Output: 14// consumed "hello" from the buffer 15// shift: 1002.652ms
1const fifo = new Fifo()
fifo.push(value): Promise
Add a value to the end of the FIFO buffer.
Returns a promise that is resolved when the pushed value is shifted off the start of the buffer.
fifo.shift(): Promise<Any>
Remove the first value from the FIFO buffer and return that removed value in a promise.
Returns a promise that resolves to a value from start of the FIFO buffer. If there are no values in the buffer the promise will resolve when a value is next pushed.
Note that multiple calls to shift when the buffer is empty will not resolve to the same value i.e. a corresponding number of calls to push
will need to be made to resolve all the promises returned by calls to shift
.
fifo.isEmpty(): Boolean
Returns true
if the FIFO buffer is empty and false
otherwise.
Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
19 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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