Skip to content

Commit

Permalink
use setImmediate on 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Mar 25, 2013
1 parent 04253f6 commit d5b3bc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
Expand Up @@ -16,6 +16,11 @@ var onexit = (function () {
return function (cb) { stack.push(cb) };
})();

var nextTick = typeof setImmediate !== 'undefined'
? setImmediate
: process.nextTick
;

exports = module.exports = createHarness();
exports.createHarness = createHarness;
exports.Test = Test;
Expand Down Expand Up @@ -71,7 +76,7 @@ function createHarness (conf_) {
});
}

process.nextTick(function () {
nextTick(function () {
if (!out.piped) out.pipe(createDefaultStream());
if (!began) out.begin();
began = true;
Expand Down Expand Up @@ -117,7 +122,7 @@ function createHarness (conf_) {
pending.unshift.apply(pending, unshifts);
}

process.nextTick(function () {
nextTick(function () {
running = false;
if (pending.length) return pending.shift()();
if (count === 0 && !closed) {
Expand Down
7 changes: 6 additions & 1 deletion lib/test.js
Expand Up @@ -5,6 +5,11 @@ var path = require('path');

module.exports = Test;

var nextTick = typeof setImmediate !== 'undefined'
? setImmediate
: process.nextTick
;

Test.prototype = new EventEmitter;

function Test (name_, opts_, cb_) {
Expand Down Expand Up @@ -137,7 +142,7 @@ Test.prototype._assert = function assert (ok, opts) {
self.emit('result', res);

if (self._plan === self.assertCount) {
process.nextTick(function () {
nextTick(function () {
if (!self.ended) self.end();
});
}
Expand Down

0 comments on commit d5b3bc2

Please sign in to comment.