Rate limit the number of tasks that can be run at any time, based on a task type.
npm install traffic-limiter --save
When creating a
Limiter, you need to specify
var Limiter = ;var limiter =foo: 1;limiter;limiter;
Complete A Task With A Ticket
Sometimes you don't have access to the
done method from the
run callback. In those cases, you can say a specific task
was completed, by using the "ticket" that is returned from the
var ticket = limiter;// later onlimitercompleteticket;
This will decrement the in-progress tasks for the specified type, allowing another task to run if needed.
You can update the limits any time you want by calling the
Update The In-Progress Count
There may be times when you have to pre-set or reset the current in-progress
count for a given task type. If you need to do this you can use the
Changing this will immediately check to see if more tasks can run.
If you would like to have unlimited tasks running, set the
limit for the type to any number below zero, such as
Stop Running Tasks For A Type
If you want to prevent tasks from running at all, for a given
type, set the limit to zero (
Traffic-Limiter is ©2015 Muted Solutions, LLC. All Rights Reserved.
Distributed under MIT License