This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change nextTick implementation for the better
Use a prepare and idle watcher to execute the nextTick callback more quickly. Test provided by Matt Ranney.
- Loading branch information
Showing
3 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require('../common'); | ||
var sys = require('sys'), i; | ||
|
||
var N = 30; | ||
var done = []; | ||
|
||
function get_printer(timeout) { | ||
return function () { | ||
sys.puts("Running from setTimeout " + timeout); | ||
done.push(timeout); | ||
}; | ||
} | ||
|
||
process.nextTick(function () { | ||
sys.puts("Running from nextTick"); | ||
done.push('nextTick'); | ||
}) | ||
|
||
for (i = 0; i < N; i += 1) { | ||
setTimeout(get_printer(i), i); | ||
} | ||
|
||
sys.puts("Running from main."); | ||
|
||
|
||
process.addListener('exit', function () { | ||
assert.equal('nextTick', done[0]); | ||
for (i = 0; i < N; i += 1) { | ||
assert.equal(i, done[i+1]); | ||
} | ||
}); |
4e7e2f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is tick_spinner only there to keep the loop alive while there are pending callbacks, since the prepare unrefd?
4e7e2f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes