Skip to content

Instantly share code, notes, and snippets.

@barcicki
Created March 19, 2017 20:57
Show Gist options
  • Save barcicki/13b4774a9ee12d5f06639e45ea5a9572 to your computer and use it in GitHub Desktop.
Save barcicki/13b4774a9ee12d5f06639e45ea5a9572 to your computer and use it in GitHub Desktop.
Call order test
function test(name, depths = 1) {
console.log(name);
if (depths > 0) {
setImmediate(() => test(`${name} > setImmediate`, depths - 1));
setTimeout(() => test(`${name} > setTimeout`, depths - 1));
process.nextTick(() => test(`${name} > nextTick`, depths - 1));
Promise.resolve().then(() => test(`${name} > resolve`, depths - 1));
}
}
test('Start', 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment