limiter-component
Advanced tools
Comparing version 0.2.2 to 1.0.0
1.0.0 / 2017-01-14 | ||
================== | ||
* process subsequent function immediately when told to skip the rest of the interval | ||
0.2.2 / 2017-01-14 | ||
@@ -3,0 +8,0 @@ ================== |
22
index.js
@@ -11,2 +11,3 @@ | ||
penaltyCounter = 0, | ||
skipCounter = 0, | ||
timer; | ||
@@ -29,3 +30,10 @@ | ||
fn(); | ||
lastTrigger = now(); | ||
// wait to the next interval unless told to skip | ||
// to the next operation immediately | ||
if (skipCounter > 0) { | ||
skipCounter = 0; | ||
} | ||
else { | ||
lastTrigger = now(); | ||
} | ||
} | ||
@@ -42,4 +50,9 @@ | ||
function schedule() { | ||
var delay; | ||
if (!timer && queue.length) { | ||
timer = setTimeout(deque, currentInterval() - since()); | ||
delay = currentInterval() - since(); | ||
if (delay < 0) { | ||
return deque(); | ||
} | ||
timer = setTimeout(deque, delay); | ||
} | ||
@@ -61,2 +74,6 @@ } | ||
function skip() { | ||
skipCounter += 1; | ||
} | ||
function cancel() { | ||
@@ -73,4 +90,5 @@ if (timer) { | ||
penalty: penalty, | ||
skip: skip, | ||
cancel: cancel | ||
}; | ||
} |
{ | ||
"name": "limiter-component", | ||
"version": "0.2.2", | ||
"version": "1.0.0", | ||
"description": "Limits the rate of function calls to one per period. It delays but does not throttle the calls.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -38,5 +38,9 @@ [![NPM version][npm-image]][npm-url] | ||
l.trigger(function() { | ||
l.penalty(); // wait a bit longer next time | ||
l.penalty(); // wait a bit longer the next time | ||
}); | ||
l.trigger(doThat); | ||
l.trigger(function() { | ||
l.skip(); // don't wait at all the next time | ||
}); | ||
l.trigger(doThis); | ||
``` | ||
@@ -59,4 +63,8 @@ | ||
Make limiter to use `penaltyInterval` before triggering next function. | ||
Make limiter use `penaltyInterval` before triggering next function. | ||
### skip() | ||
Make limiter trigger next function immediately. | ||
### cancel() | ||
@@ -63,0 +71,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5701
74
1
85
1