throttled-queue
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "throttled-queue", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Throttles arbitrary code to execute a maximum number of times per interval. Best for making throttled API requests.", | ||
@@ -5,0 +5,0 @@ "main": "throttled-queue.js", |
@@ -22,8 +22,8 @@ "use strict"; | ||
* | ||
* @param max_requests_per_interval | ||
* @param maxRequestPerInterval | ||
* @param interval | ||
* @param evenly_spaced | ||
* @param evenlySpaced | ||
* @returns {Function} | ||
*/ | ||
var throttledQueue = function(max_requests_per_interval, interval, evenly_spaced) { | ||
var throttledQueue = function(maxRequestPerInterval, interval, evenlySpaced) { | ||
@@ -33,5 +33,5 @@ /** | ||
*/ | ||
if (evenly_spaced) { | ||
interval = interval / max_requests_per_interval; | ||
max_requests_per_interval = 1; | ||
if (evenlySpaced) { | ||
interval = interval / maxRequestPerInterval; | ||
maxRequestPerInterval = 1; | ||
} | ||
@@ -44,3 +44,4 @@ | ||
var queue = []; | ||
var last_called = Date.now(); | ||
var lastCalled = Date.now(); | ||
var timeout; | ||
@@ -54,3 +55,3 @@ /** | ||
var threshold = last_called + interval; | ||
var threshold = lastCalled + interval; | ||
var now = Date.now(); | ||
@@ -67,3 +68,3 @@ | ||
var callbacks = queue.splice(0, max_requests_per_interval); | ||
var callbacks = queue.splice(0, maxRequestPerInterval); | ||
for(var x = 0; x < callbacks.length; x++) { | ||
@@ -73,16 +74,14 @@ callbacks[x](); | ||
last_called = Date.now(); | ||
timeout = setTimeout(dequeue, interval); | ||
lastCalled = Date.now(); | ||
if (queue.length) { | ||
timeout = setTimeout(dequeue, interval); | ||
} | ||
}; | ||
/** | ||
* Kick off the timer. | ||
*/ | ||
var timeout = setTimeout(dequeue, interval); | ||
return function enqueue(callback) { | ||
/** | ||
* Return a function that can enqueue items. | ||
*/ | ||
return function(callback) { | ||
queue.push(callback); | ||
if (!timeout) { | ||
timeout = setTimeout(dequeue, interval); | ||
} | ||
}; | ||
@@ -111,2 +110,2 @@ }; | ||
}).call(this); | ||
}).call(this); |
@@ -1,1 +0,1 @@ | ||
"use strict";(function(){var e,t="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this;null!=t&&(e=t.throttledQueue);var o=function(e,t,o){o&&(t/=e,e=1),200>t&&console.warn("An interval of less than 200ms can create performance issues.");var n=[],l=Date.now(),u=function(){var o=l+t,f=Date.now();if(o>f)return clearTimeout(r),void(r=setTimeout(u,o-f));for(var i=n.splice(0,e),s=0;s<i.length;s++)i[s]();l=Date.now(),r=setTimeout(u,t)},r=setTimeout(u,t);return function(e){n.push(e)}};o.noConflict=function(){return t.throttledQueue=e,o},"object"==typeof module&&module.exports?module.exports=o:"function"==typeof define&&define.amd?define([],function(){return o}):t.throttledQueue=o}).call(this); | ||
"use strict";(function(){var e,t="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this;null!=t&&(e=t.throttledQueue);var o=function(e,t,o){o&&(t/=e,e=1),t<200&&console.warn("An interval of less than 200ms can create performance issues.");var n,l=[],u=Date.now(),r=function(){var o=u+t,f=Date.now();if(f<o)return clearTimeout(n),void(n=setTimeout(r,o-f));for(var i=l.splice(0,e),s=0;s<i.length;s++)i[s]();u=Date.now(),l.length&&(n=setTimeout(r,t))};return function(e){l.push(e),n||(n=setTimeout(r,t))}};o.noConflict=function(){return t.throttledQueue=e,o},"object"==typeof module&&module.exports?module.exports=o:"function"==typeof define&&define.amd?define([],function(){return o}):t.throttledQueue=o}).call(this); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42007
15