Skip to content
Browse files

0.1.1

  • Loading branch information...
1 parent 4f6210b commit ccbe226958e4791ef30afeaf74c1d8fb00cfd537 @rook2pawn committed Oct 17, 2011
Showing with 36 additions and 2 deletions.
  1. +6 −0 README.md
  2. +11 −1 index.js
  3. +2 −1 package.json
  4. +17 −0 test/test.js
View
6 README.md
@@ -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
=================
View
12 index.js
@@ -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) {
@@ -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');
@@ -75,7 +80,7 @@ function qlib(obj) {
myWorkFunction = fn;
} else if ((fn === undefined) && (work !== undefined)) {
myWorkFunction = work;
- }
+ }
myWorkFunction.apply(myWorkFunction,[element,self]);
}
};
@@ -109,6 +114,7 @@ function qlib(obj) {
obj.el = transform(el);
}
queue.push(obj);
+ shadowQueue.push(obj);
if (governor !== undefined) {
governor(queue,self);
}
@@ -133,6 +139,7 @@ function qlib(obj) {
obj.el = transform(el);
}
queue.push(obj);
+ shadowQueue.push(obj);
if (governor !== undefined) {
governor(queue,self);
}
@@ -199,5 +206,8 @@ function qlib(obj) {
self.flags = function() {
return obj;
};
+ self.getVelocity = function() {
+ return shadowQueue.getVelocity('push');
+ };
return self;
};
View
3 package.json
@@ -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",
@@ -11,6 +11,7 @@
"main": "index.js",
"dependencies": {
"textual" : ">=v0.0.1"
+ "velocity" : ">=v0.0.1"
},
"devDependencies": {}
}
View
17 test/test.js
@@ -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.
Something went wrong with that request. Please try again.