@snickbit/queue
v1.3.10
Published
Fluid queueing library for any function or promise
Downloads
78
Readme
@snickbit/queue
Fluid queueing library for any function or promise
Installation
pnpm add @snickbit/queue
yarn add @snickbit/queue
npm i @snickbit/queue
Basic Usage
Initialize
import {queue} from '@snickbit/queue'
// or const {queue} = require('@snickbit/queue')
const $queue = queue({concurrency: 25, limit: 5, interval: 1000, strict: true})
or as a class with
import {Queue} from '@snickbit/queue'
const $queue = new Queue({concurrency: 5})
Add some Promises or functions to the queue
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))
for (let i = 0; i < 100; i++) {
$queue.push(async () => {
await sleep(Math.random() * 100)
console.log(`${i}`)
})
}
$queue.run()
.then(() => console.log('done'))
.catch((err) => console.error('Oops', err))
// or await $queue.run()
thenEach (callback)
Attaches a callback for the resolution of each Promise or Function in the queue.
catchEach (callback)
Attaches a callback for the rejection of each Promise or Function in the queue.
finallyEach (callback)
Attaches a callback that is invoked when each Promise or Function in the queue is settled (fulfilled or rejected).
Check the API Docs for more details
Documentation
API Docs
CHANGELOG
Acknowledgements
License
Copyright (c) 2022 - Nicholas Lowe aka Snickbit