Skip to content

Commit

Permalink
added dependency to introspect module
Browse files Browse the repository at this point in the history
  • Loading branch information
kilianc committed Nov 22, 2011
1 parent 5ad11c5 commit fdbe16f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ new FnQueue(functionsList[, callback, concurrencyLevel, isStopped]);
FnQueue runs a list of functions, each passing their results to the dependent function in the list. However, if any of the functions pass an error to the callback, the next function is not executed and the main callback is immediately called with the error.

Each dependency/argument must be named with the label of the dependent function in the `functionsList` (the first constructor argument).
Each function with a dependency will be called with the result of the dependent function as expected. __(YES this is a fucking cool introspection!)__
Each function with a dependency will be called with the result of the dependent function as expected. __(Introspection by [introspect](https://github.com/kilianc/introspect))__

The global callback is called once, on the first error or at the end of the execution. A data object will be provided with the indexed result of the functions.

Expand Down Expand Up @@ -90,14 +90,6 @@ new FnQueue({
}, 1);
```

##Introspection profiling results

Profiling results are pretty good, Function.toString() took up __2~ seconds__ every __1 Million__ of executions.

Lines of code time (ms) Platform
---------------------------------------------------------------------------------------------------
800 1808ms OSX Lion 2.2 GHz Intel Core i7 / nodejs v6.0.1

## Test

Tests depends on http://vowsjs.org/ then
Expand All @@ -106,7 +98,7 @@ Tests depends on http://vowsjs.org/ then
npm install
npm test

![tests](http://f.cl.ly/items/3q2W11392o2G2r0d0413/fnqueue_test_v2.0.1.png)
![tests](http://f.cl.ly/items/03432M3A0l0r3M142B2w/fnqueue_test_v2.0.2.png)

## License

Expand Down
9 changes: 4 additions & 5 deletions lib/fnqueue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var
introspect = require('introspect');

function FnQueue(tasks, callback, concurrecyLevel, isStopped) {
this.tasks = tasks;
this.taskDependencies = {};
Expand Down Expand Up @@ -44,7 +47,7 @@ FnQueue.prototype.loadDependencies = function() {
return;
}

this.taskDependencies[taskName] = this.getFunctionArguments(this.tasks[taskName]).slice(0, -1);
this.taskDependencies[taskName] = introspect(this.tasks[taskName]).slice(0, -1);
}
};

Expand Down Expand Up @@ -119,10 +122,6 @@ FnQueue.prototype.callNextFunction = function () {

FnQueue.prototype.start = FnQueue.prototype.callNextFunction;

FnQueue.prototype.getFunctionArguments = function (fn) {
return (/^function.+\(([a-z0-9\n\r\t ,]*)\)/i).exec(fn.toString())[1].trim().split(/[ ,\n\r\t]+/);
};

FnQueue.prototype.getDependencies = function (dependencies) {

var args = [];
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"type": "git",
"url": "http://github.com/kilianc/node-fnqueue.git"
},
"dependencies": {
"introspect": "0.0.x"
},
"devDependencies": {
"vows": "0.5.x >= 0.5.13"
}
Expand Down
21 changes: 0 additions & 21 deletions test/fnqueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ vows.describe('FnQueue').addBatch({
assert.isFalse(prototype.isVerbose);
}
}
}).addBatch({
'FnQueue.getFunctionArguments should success': {
'without spaces': function () {
assert.deepEqual(FnQueue.prototype.getFunctionArguments(function (foo,bar,callback) {}), ['foo', 'bar', 'callback']);
},
'with spaces': function () {
assert.deepEqual(FnQueue.prototype.getFunctionArguments(function ( foo , bar , callback ) { }), ['foo', 'bar', 'callback']);
},
'with newline': function () {
assert.deepEqual(FnQueue.prototype.getFunctionArguments(function (
foo,
bar,
callback
) {//foo bar
//foo bar
var a = 5;
for(var b = 0; b < 1000; b ++) { }
if (a == 5) { }
}), ['foo', 'bar', 'callback']);
}
}
}).addBatch({
'Given an object of results': {
topic: {
Expand Down

0 comments on commit fdbe16f

Please sign in to comment.