Comparing version 1.0.73 to 1.0.75
{ | ||
"name": "yow", | ||
"version": "1.0.73", | ||
"version": "1.0.75", | ||
"description": "You Only Wish module", | ||
@@ -5,0 +5,0 @@ "main": "yow.js", |
35
queue.js
@@ -6,6 +6,6 @@ var isArray = require('./yow.js').isArray; | ||
var _this = this; | ||
var _queue = []; | ||
var _promise = undefined; | ||
var _limit = limit == undefined ? 1000 : limit; | ||
var _this = this; | ||
var _queue = []; | ||
var _running = false; | ||
var _limit = limit == undefined ? 1000 : limit; | ||
@@ -15,9 +15,13 @@ _this.dequeue = function() { | ||
return new Promise(function(resolve, reject) { | ||
if (_queue.length > 0 && _promise == undefined) { | ||
if (_queue.length > 0 && !_running) { | ||
_promise = _queue.splice(0, 1)[0]; | ||
_running = true; | ||
_promise.then(function() { | ||
_promise = undefined; | ||
// Get next function in line | ||
var fn = _queue.splice(0, 1)[0]; | ||
// Call it, and wait for complete | ||
fn().then(function() { | ||
_running = false; | ||
function recurse() { | ||
@@ -35,2 +39,3 @@ _this.dequeue().then(function() { | ||
.catch(function(error) { | ||
_running = false; | ||
reject(error); | ||
@@ -66,3 +71,3 @@ }); | ||
_this.isRunning = function() { | ||
return _promise != undefined; | ||
return _running; | ||
}; | ||
@@ -74,10 +79,10 @@ | ||
this.prequeue = function(promise) { | ||
this.prequeue = function(fn) { | ||
if (_queue.length > _limit) { | ||
console.log('Queue too big! Truncating.'); | ||
_queue = [promise]; | ||
_queue = [fn]; | ||
} | ||
else { | ||
_queue.unshift(promise); | ||
_queue.unshift(fn); | ||
@@ -88,10 +93,10 @@ } | ||
this.enqueue = function(promise) { | ||
this.enqueue = function(fn) { | ||
if (_queue.length > _limit) { | ||
console.log('Queue too big! Truncating.'); | ||
_queue = [promise]; | ||
_queue = [fn]; | ||
} | ||
else { | ||
_queue.push(promise); | ||
_queue.push(fn); | ||
@@ -98,0 +103,0 @@ } |
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
22101
551