Permalink
Browse files

Allow optional arguments to be passed to process.nextTick.

  • Loading branch information...
1 parent 8838e14 commit 1ff3b286cc97c7f396504c8f7665a202d04fbb70 @tobie committed Mar 1, 2011
Showing with 32 additions and 5 deletions.
  1. +4 −4 doc/api/process.markdown
  2. +10 −1 src/node.js
  3. +18 −0 test/simple/test-next-tick-extra-args.js
View
@@ -296,11 +296,11 @@ This will generate:
`heapTotal` and `heapUsed` refer to V8's memory usage.
-### process.nextTick(callback)
+### process.nextTick(callback, [args], [...])
-On the next loop around the event loop call this callback.
-This is *not* a simple alias to `setTimeout(fn, 0)`, it's much more
-efficient.
+On the next loop around the event loop call this callback. Optionally, you
+can also pass arguments to the callback. This is *not* a simple alias to
+`setTimeout(fn, 0)`, it's much more efficient.
process.nextTick(function () {
console.log('nextTick callback');
View
@@ -119,8 +119,17 @@
nextTickQueue.splice(0, l);
};
+ var pSlice = Array.prototype.slice;
+
process.nextTick = function(callback) {
- nextTickQueue.push(callback);
+ if (arguments.length == 1) {
+ nextTickQueue.push(callback);
+ } else {
+ var args = pSlice.call(arguments, 1);
+ nextTickQueue.push(function() {
+ callback.apply(null, args);
+ });
+ }
process._needTickCallback();
};
};
@@ -0,0 +1,18 @@
+var common = require('../common');
+var assert = require('assert');
+
+var argumentsLength, firstArg, secondArg;
+
+function callback() {
+ argumentsLength = arguments.length;
+ firstArg = arguments[0];
+ secondArg = arguments[1];
+}
+
+process.nextTick(callback, 123, 456);
+
+process.addListener('exit', function() {
+ assert.equal(2, argumentsLength);
+ assert.equal(123, firstArg);
+ assert.equal(456, secondArg);
+});

0 comments on commit 1ff3b28

Please sign in to comment.