Permalink
Browse files

support unlimited number of arguments for callback functions

  • Loading branch information...
1 parent d4be2e4 commit 6566283fd7564054d7a2c0d9d7de686918bc33ab @bkw bkw committed Mar 14, 2012
Showing with 40 additions and 3 deletions.
  1. +5 −0 History.md
  2. +3 −2 lib/poolr.js
  3. +1 −1 package.json
  4. +31 −0 test/test-callback-arguments.js
View
@@ -22,3 +22,8 @@
* only emit 'idle' when queue length is zero (Seth LaForge)
* fix tests and move to bdd
+0.0.7 / 2012-03-14
+==================
+
+ * support unlimited number of arguments for callback functions
+
View
@@ -63,12 +63,13 @@ Poolr.prototype.runNext = function () {
this.throttled = false;
this.emit('drain');
}
- job.job(function (err, res) {
+ job.job(function () {
+ var args = Array.prototype.slice.call(arguments);
this.runningJobs --;
process.nextTick(function () {
this.runNext();
}.bind(this));
- var result = job.callback(err, res);
+ var result = job.callback.apply(null, args);
if (this.runningJobs < 1 && this.queue.length === 0) {
this.emit('idle');
}
View
@@ -1,6 +1,6 @@
{
"name": "poolr",
- "version": "0.0.6",
+ "version": "0.0.7",
"description": "limit parallel execution and serialze when limit is reached",
"homepage": "https://github.com/codingforce/poolr",
"repository": {
@@ -0,0 +1,31 @@
+var should = require('should')
+ , poolr = require('../lib/poolr.js')
+ , testfunc = function(i,callback) {
+ process.nextTick(function(){return callback(i,i+1,i+2)});
+ }
+ ;
+
+describe('poolr', function() {
+ var testPool = poolr.createPool(5);
+ describe('callbacks', function() {
+ it('should be called with correct arguments', function(done) {
+ var outstanding = 0;
+
+ for (var i=0; i<10; i++) {
+ outstanding++;
+ (function(i){
+ testPool.addTask(testfunc,i,function(a,b,c) {
+ a.should.eql(i);
+ b.should.eql(i+1);
+ c.should.eql(i+2);
+ if (--outstanding === 0) {
+ done();
+ }
+ });
+ })(i);
+ }
+ });
+ });
+});
+
+

0 comments on commit 6566283

Please sign in to comment.