+1
-1
| language: node_js | ||
| node_js: | ||
| - 0.4 | ||
| - 0.6 | ||
| - 0.8 |
+25
-9
@@ -21,3 +21,2 @@ var EventEmitter = require('events').EventEmitter | ||
| this._timers = []; | ||
| this._active = 0; | ||
| }; | ||
@@ -29,2 +28,14 @@ | ||
| /** | ||
| * How many tasks are currently active. | ||
| */ | ||
| TimeQueue.prototype.active = 0; | ||
| /** | ||
| * How many tasks are in the queue. | ||
| */ | ||
| TimeQueue.prototype.queued = 0; | ||
| /** | ||
| * Pushes a task onto the queue. | ||
@@ -36,4 +47,4 @@ * | ||
| TimeQueue.prototype.push = function() { | ||
| if (this._active < this.concurrency) { | ||
| if (++this._active === this.concurrency) { | ||
| if (this.active < this.concurrency) { | ||
| if (++this.active === this.concurrency) { | ||
| this.emit('full'); | ||
@@ -44,2 +55,3 @@ } | ||
| this._queue.push(arguments); | ||
| this.queued++; | ||
| } | ||
@@ -54,4 +66,4 @@ }; | ||
| */ | ||
| TimeQueue.prototype._process = function(arguments) { | ||
| var args = Array.prototype.slice.call(arguments); | ||
| TimeQueue.prototype._process = function(args) { | ||
| args = Array.prototype.slice.call(args); | ||
| var callback = args.splice(this.worker.length - 1, 1)[0]; | ||
@@ -62,4 +74,5 @@ var self = this; | ||
| var time = ~~this.time; | ||
| var timedOut; | ||
| if (time) { | ||
| var timedOut = false; | ||
| timedOut = false; | ||
@@ -75,3 +88,3 @@ self._timers.push(setTimeout(function() { | ||
| } else { | ||
| var timedOut = true; | ||
| timedOut = true; | ||
| } | ||
@@ -113,4 +126,5 @@ | ||
| TimeQueue.prototype._next = function() { | ||
| if (this._active <= this.concurrency && this._queue.length) { | ||
| if (this.active <= this.concurrency && this._queue.length) { | ||
| var task = this._queue.shift(); | ||
| this.queued--; | ||
| this._process(task); | ||
@@ -122,3 +136,3 @@ | ||
| } else if (--this._active === 0) { | ||
| } else if (--this.active === 0) { | ||
| this.emit('drain'); | ||
@@ -136,2 +150,4 @@ } | ||
| this._timers = []; | ||
| this.active = 0; | ||
| this.queued = 0; | ||
| }; |
+2
-5
@@ -5,3 +5,3 @@ { | ||
| "keywords": ["queue", "flow", "time"], | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "repository": { | ||
@@ -19,7 +19,4 @@ "type": "git", | ||
| }, | ||
| "engines": { | ||
| "node": "*" | ||
| }, | ||
| "devDependencies": { | ||
| "mocha": "0.x.x" | ||
| "mocha": "x" | ||
| }, | ||
@@ -26,0 +23,0 @@ "licenses": [ { |
+9
-4
@@ -35,2 +35,10 @@ # timequeue.js [](http://travis-ci.org/fent/timequeue.js) | ||
| ### TimeQueue#active | ||
| How many tasks are currently active. | ||
| ### TimeQueue#queued | ||
| How many tasks are currently in the queue. | ||
| ### TimeQueue#push(data..., [callback]) | ||
@@ -45,3 +53,3 @@ Pushes a new task to the queue. Any number of arguments can be given. An optional callback can also be given as the last parameter. The callback will be called when the task is finished or if there was any error. | ||
| ### Event: 'error' | ||
| `function (err) { }` | ||
| * `Error` | ||
@@ -51,3 +59,2 @@ Emitted when there is an error processing a task and a callback isn't given to the `push` method. | ||
| ### Event: 'full' | ||
| `function () { }` | ||
@@ -57,3 +64,2 @@ Queue is full. | ||
| ### Event: 'empty' | ||
| `function () { }` | ||
@@ -63,3 +69,2 @@ Queue is empty, some tasks might still be running. | ||
| ### Event: 'drain' | ||
| `function () { }` | ||
@@ -66,0 +71,0 @@ Queue is empty and last task has finished. |
+13
-6
@@ -26,2 +26,3 @@ var TimeQueue = require('..') | ||
| assert.equal(full, false); | ||
| assert.equal(q.queued, 0); | ||
@@ -31,2 +32,3 @@ q.push(); | ||
| assert.equal(full, false); | ||
| assert.equal(q.queued, 0); | ||
@@ -36,2 +38,3 @@ q.push(); | ||
| assert.equal(full, true); | ||
| assert.equal(q.queued, 0); | ||
@@ -41,2 +44,3 @@ q.push(); | ||
| assert.equal(full, true); | ||
| assert.equal(q.queued, 1); | ||
@@ -46,2 +50,3 @@ q.push(); | ||
| assert.equal(full, true); | ||
| assert.equal(q.queued, 2); | ||
@@ -51,4 +56,8 @@ q.push(); | ||
| assert.equal(full, true); | ||
| assert.equal(q.queued, 3); | ||
| q.on('drain', done); | ||
| q.on('drain', function() { | ||
| assert.equal(q.active, 0); | ||
| done(); | ||
| }); | ||
| }); | ||
@@ -126,3 +135,3 @@ }); | ||
| it('Emits an `error` event', function(done) { | ||
| q.push('whatever'); | ||
| q.push(); | ||
| q.once('error', function(err) { | ||
@@ -135,6 +144,4 @@ assert.equal(err.message, 'gotcha'); | ||
| describe('Push task with callback', function() { | ||
| it('Does not emit `error` event, calls calback with error', function(done) { | ||
| q.once('error', function(err) { | ||
| throw err; | ||
| }); | ||
| it('Does not emit `error`, calls callback with error', function(done) { | ||
| q.once('error', done); | ||
@@ -141,0 +148,0 @@ q.push(function(err) { |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
11244
3.89%279
7.31%83
6.41%