putil-taskqueue
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -10,65 +10,68 @@ /* putil-taskqueue | ||
/** | ||
* @class | ||
* @public | ||
* Expose `TaskQueue`. | ||
*/ | ||
class TaskQueue { | ||
module.exports = TaskQueue; | ||
constructor(options) { | ||
this._queue = []; | ||
this._cancelOnError = options.cancelOnError; | ||
} | ||
/** | ||
* Module dependencies. | ||
* @private | ||
*/ | ||
/** | ||
* | ||
* @param {Function} resolver | ||
*/ | ||
enqueue(resolver) { | ||
this._queue.push(resolver); | ||
this.next(); | ||
} | ||
function TaskQueue(options) { | ||
this._queue = []; | ||
this._cancelOnError = options.cancelOnError; | ||
} | ||
/** | ||
* | ||
* @param {Function} resolver | ||
*/ | ||
enqueueTop(resolver) { | ||
this._queue.splice(0, 0, resolver); | ||
this.next(); | ||
} | ||
const proto = TaskQueue.prototype = {}; | ||
proto.constructor = TaskQueue; | ||
next() { | ||
const self = this; | ||
if (self._taskRunning) return; | ||
/** | ||
* | ||
* @param {Function} resolver | ||
*/ | ||
proto.enqueue = function(resolver) { | ||
this._queue.push(resolver); | ||
this.next(); | ||
}; | ||
if (!self._queue.length) | ||
self._taskRunning = false; | ||
else { | ||
const fn = self._queue.shift(); | ||
self._taskRunning = true; | ||
setImmediate(() => { | ||
try { | ||
fn(() => { | ||
self._taskRunning = false; | ||
self.next(); | ||
}); | ||
} catch (e) { | ||
/** | ||
* | ||
* @param {Function} resolver | ||
*/ | ||
proto.enqueueTop = function(resolver) { | ||
this._queue.splice(0, 0, resolver); | ||
this.next(); | ||
}; | ||
proto.next = function() { | ||
const self = this; | ||
if (self._taskRunning) return; | ||
if (!self._queue.length) | ||
self._taskRunning = false; | ||
else { | ||
const fn = self._queue.shift(); | ||
self._taskRunning = true; | ||
setImmediate(function() { | ||
try { | ||
fn(function() { | ||
self._taskRunning = false; | ||
if (self._cancelOnError) | ||
self.clear(); | ||
throw e; | ||
} | ||
}); | ||
} | ||
self.next(); | ||
}); | ||
} catch (e) { | ||
self._taskRunning = false; | ||
if (self._cancelOnError) | ||
self.clear(); | ||
throw e; | ||
} | ||
}); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
clear() { | ||
this._queue = []; | ||
} | ||
} | ||
module.exports = TaskQueue; | ||
/** | ||
* | ||
*/ | ||
proto.clear = function() { | ||
this._queue = []; | ||
}; |
{ | ||
"name": "putil-taskqueue", | ||
"description": "Very simple async task queue for ES6", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"author": "Panates Ltd.", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
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
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
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
5076
66
1