@sugarcoated/fondant-queue
v1.0.0
Published
Queue asynchronous logic.
Readme
Method queues are a common pattern for throttling the execution of methods, so that one will only execute after the other, in a controller manner. Queue brings that to asynchronous logic such as Promise and async/await. Task the queue with methods you want to throttle in this way, and handle the Promise usually expected like you would without.
- View the source for Queue at: src/actionables/Queue.js.
- View the test file for Queue at: tests/Actionables/testQueue.js.
- View the NPM package at: @sugarcoated/fondant-queue.
API Reference
Instance Methods
`new Queue([max])
Create a new Queue.
maxis an optional parameter, expected as aNumber, representing the maximum amount ofAsyncFunctions orFunction.<Promise>theQueuecan hold at any one time.new Queue() new Queue(20)
Upon construction, you will have access to the following properties:
pendingis the current amount of pendingPromises.maximumis the maximum amount of pendingPromises allowed.
.task(method)
Add a method to the Queue.
methodis expected as aFunctionthat returns aPromise. This can be anAsyncFunction.myQueue.task(async () => {}).then().catch() myQueue.task(() => new Promise(() => {})).then().catch()
.pretask(method)
Add a method to the front of the Queue.
methodis expected as aFunctionthat returns aPromise. This can be anAsync Function.myQueue.pretask(async () => {}).then().catch() myQueue.pretask(() => new Promise(() => {})).then().catch()
Instance Events
Emptyis fired when theQueueresolves the finalPreomise.
