Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rook2pawn committed Oct 17, 2011
1 parent 4f6210b commit ccbe226
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ Use this option when the nodelete flag is specified.
--------
Returns the most current copy of the entire queue.

.getVelocity()
--------------

Returns the rate in pushes per second (rounded via Math.floor) on the queue.


The Work Function
=================

Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var EventEmitter = require('events').EventEmitter;
var textual = require('textual');
var Velocity = require('velocity');
exports = module.exports = qlib;
function qlib(obj) {
var emitter = new EventEmitter;
var speed = Velocity();
var paused = noDeleteOnNext = autoNext = false;
var work,onNext = undefined;
if (obj !== undefined) {
Expand All @@ -12,6 +14,9 @@ function qlib(obj) {
onNext = obj.onNext || undefined;
}
var queue = [];
var shadowQueue = []; // strictly for speed watching
shadowQueue = speed.watch(shadowQueue);
shadowQueue.follow('push');
if (noDeleteOnNext) queue.next = 0;
var sort,transform,governor,sortall = undefined;
var nextListeners = emitter.listeners('next');
Expand Down Expand Up @@ -75,7 +80,7 @@ function qlib(obj) {
myWorkFunction = fn;
} else if ((fn === undefined) && (work !== undefined)) {
myWorkFunction = work;
}
}
myWorkFunction.apply(myWorkFunction,[element,self]);
}
};
Expand Down Expand Up @@ -109,6 +114,7 @@ function qlib(obj) {
obj.el = transform(el);
}
queue.push(obj);
shadowQueue.push(obj);
if (governor !== undefined) {
governor(queue,self);
}
Expand All @@ -133,6 +139,7 @@ function qlib(obj) {
obj.el = transform(el);
}
queue.push(obj);
shadowQueue.push(obj);
if (governor !== undefined) {
governor(queue,self);
}
Expand Down Expand Up @@ -199,5 +206,8 @@ function qlib(obj) {
self.flags = function() {
return obj;
};
self.getVelocity = function() {
return shadowQueue.getVelocity('push');
};
return self;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "David Wee <rook2pawn@gmail.com> (http://rook2pawn.com)",
"name": "queuelib",
"description": "Fast event driven Queue processor - FIFO over asynchronous functions with Flow control!",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/rook2pawn/node-queuelib",
"repository": {
"type": "git",
Expand All @@ -11,6 +11,7 @@
"main": "index.js",
"dependencies": {
"textual" : ">=v0.0.1"
"velocity" : ">=v0.0.1"
},
"devDependencies": {}
}
17 changes: 17 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,20 @@ exports.testPauseOnMixed = function(test) {
test.expect(0);
test.done();
};

exports.testVelocity = function(test) {
test.expect(1);
var q = qlib({work:function(el){}});
q.pushSync('foo');
setTimeout(function() {
q.pushSync('bar');
setTimeout(function() {
q.pushSync('baz');
setTimeout(function() {
q.pushSync('qux');
test.equals(4,q.getVelocity('push'));
test.done();
},210);
},210);
},210);
};

0 comments on commit ccbe226

Please sign in to comment.