Socket
Socket
Sign inDemoInstall

vow-queue

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

1

.jscs.json

@@ -10,3 +10,2 @@ {

"disallowMulipleLineBreaks": true,
"disallowKeywordsOnNewLine": ["else"],
"requireAlignedObjectValues": "skipWithLineBreak",

@@ -13,0 +12,0 @@ "validateJSDoc": {

68

lib/queue.js
/**
* @module vow-queue
* @author Filatov Dmitry <dfilatov@yandex-team.ru>
* @version 0.1.0
* @version 0.2.0
* @license

@@ -26,2 +26,3 @@ * Dual licensed under the MIT and GPL licenses:

},
nextTick = typeof setImmediate !== 'undefined'? setImmediate : process.nextTick,

@@ -51,2 +52,4 @@ DEFAULT_QUEUE_PARAMS = {

this._isRunScheduled = false;
this._isStopped = true;
this._processedBuffer = [];
};

@@ -56,3 +59,3 @@

/**
* Add task to queue
* Adds task to queue
*

@@ -76,3 +79,3 @@ * @param {Function} taskFn

this._enqueueTask(task);
this._scheduleRun();
this._isStopped || this._scheduleRun();

@@ -83,3 +86,40 @@ return task.defer.promise();

/**
* Set params of queue
* Starts processing of queue
*/
start : function() {
if(!this._isStopped) {
return;
}
this._isStopped = false;
var processedBuffer = this._processedBuffer;
if(processedBuffer.length) {
this._processedBuffer = [];
nextTick(function() {
while(processedBuffer.length) {
processedBuffer.shift()();
}
});
}
this._hasPendingTasks() && this._scheduleRun();
},
/**
* Stops processing of queue
*/
stop : function() {
this._isStopped = true;
},
/**
* Checks whether the queue is started
* @returns {Boolean}
*/
isStarted : function() {
return !this._isStopped;
},
/**
* Sets params of queue
*

@@ -124,3 +164,3 @@ * @param {Object} params

this._isRunScheduled = true;
process.nextTick(this._run.bind(this));
nextTick(this._run.bind(this));
}

@@ -131,3 +171,3 @@ },

this._isRunScheduled = false;
while(this._pendingTasks.length && this._allowRunTask(this._pendingTasks[0])) {
while(this._hasPendingTasks() && this._allowRunTask(this._pendingTasks[0])) {
this._runTask(this._pendingTasks.shift());

@@ -137,2 +177,6 @@ }

_hasPendingTasks : function() {
return !!this._pendingTasks.length;
},
_allowRunTask : function(task) {

@@ -149,8 +193,14 @@ return this._curWeight + task.params.weight <= this._params.weightLimit;

this._curWeight -= task.params.weight;
this._scheduleRun();
if(this._isStopped) {
this._processedBuffer.push(function() {
task.defer.resolve(taskRes);
});
}
else {
task.defer.resolve(taskRes);
this._scheduleRun();
}
},
this);
task.defer.resolve(taskRes);
}
};
{
"name" : "vow-queue",
"author" : "Dmitry Filatov <dfilatov@yandex-team.ru>",
"description" : "Short package description",
"name" : "vow-queue",
"version" : "0.1.0",
"description" : "Vow-based task queue",
"version" : "0.2.0",
"contributors" : [

@@ -7,0 +7,0 @@ {

vow-queue
===============
Simple queue with weights and priorities
vow-queue is a module for task queue with weights and priorities

@@ -9,3 +9,3 @@ Installation

Vow-queue can be installed using `npm`:
Module can be installed using `npm`:

@@ -40,2 +40,6 @@ ```

});
queue.start(); // starts tasks processing
queue.enqueue(function() { }); // and enqueue yet another task
````

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc