Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

putil-taskqueue

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

putil-taskqueue - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

111

lib/taskqueue.js

@@ -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": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc