2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
2010-12-06 03:15:30 +08:00
|
|
|
var assert = require('assert');
|
2010-10-12 05:04:09 +08:00
|
|
|
var i;
|
2010-04-14 06:39:15 +08:00
|
|
|
|
2011-01-31 07:22:42 +08:00
|
|
|
var N = 333;
|
2010-04-14 06:39:15 +08:00
|
|
|
var done = [];
|
|
|
|
|
|
|
|
function get_printer(timeout) {
|
2010-12-03 09:03:18 +08:00
|
|
|
return function() {
|
|
|
|
console.log('Running from setTimeout ' + timeout);
|
2010-04-14 06:39:15 +08:00
|
|
|
done.push(timeout);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
process.nextTick(function() {
|
|
|
|
console.log('Running from nextTick');
|
2010-04-14 06:39:15 +08:00
|
|
|
done.push('nextTick');
|
2010-12-03 09:03:18 +08:00
|
|
|
});
|
2010-04-14 06:39:15 +08:00
|
|
|
|
|
|
|
for (i = 0; i < N; i += 1) {
|
|
|
|
setTimeout(get_printer(i), i);
|
|
|
|
}
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('Running from main.');
|
2010-04-14 06:39:15 +08:00
|
|
|
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
process.addListener('exit', function() {
|
2010-04-14 06:39:15 +08:00
|
|
|
assert.equal('nextTick', done[0]);
|
|
|
|
for (i = 0; i < N; i += 1) {
|
2010-12-03 09:03:18 +08:00
|
|
|
assert.equal(i, done[i + 1]);
|
2010-04-14 06:39:15 +08:00
|
|
|
}
|
|
|
|
});
|