-
-
Save isaacs/7206752 to your computer and use it in GitHub Desktop.
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
var isset = false | |
var interval | |
var assert = require('assert') | |
var doNT = !!process.argv[2] | |
function set() { | |
console.error(arguments.callee.name) | |
assert(!isset) | |
isset = true | |
interval = setInterval(intFn) | |
} | |
function clear() { | |
console.error(arguments.callee.name) | |
assert(isset) | |
isset = false | |
if (doNT) | |
process.nextTick(clear_) | |
else | |
clear_() | |
} | |
function clear_() { | |
console.error(arguments.callee.name) | |
clearInterval(interval) | |
} | |
function intFn() { | |
console.error(arguments.callee.name) | |
assert(isset) | |
timeouts() | |
} | |
function timeouts() { | |
console.error(arguments.callee.name) | |
setTimeout(toFn) | |
setTimeout(toFn) | |
setTimeout(toFn) | |
} | |
function toFn() { | |
console.error(arguments.callee.name) | |
if (!isset) | |
set() | |
else | |
clear() | |
} | |
toFn() | |
/* | |
$ ./node x.js | |
toFn | |
set | |
intFn | |
timeouts | |
toFn | |
clear | |
clear_ | |
toFn | |
set | |
toFn | |
clear | |
clear_ | |
$ ./node x.js helloyesthisisnexttick | |
toFn | |
set | |
intFn | |
timeouts | |
toFn | |
clear | |
toFn | |
set | |
toFn | |
clear | |
intFn | |
assert.js:98 | |
throw new assert.AssertionError({ | |
^ | |
AssertionError: false == true | |
at intFn (/Users/isaacs/dev/js/node-master/x.js:30:3) | |
at wrapper [as _onTimeout] (timers.js:249:14) | |
at Timer.listOnTimeout (timers.js:107:15) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment