Skip to content

Instantly share code, notes, and snippets.

@PaulRosset
Forked from peaBerberian/exercice.js
Last active April 6, 2020 17:43
Show Gist options
  • Save PaulRosset/e8e6c9770f37978b0ba009ac01fb115d to your computer and use it in GitHub Desktop.
Save PaulRosset/e8e6c9770f37978b0ba009ac01fb115d to your computer and use it in GitHub Desktop.
Understand EventLoop on async operation for Scheduler in rxjs
/**
* Using process.nextTick(() => {})
* Permit to launch a microtask inside the eventloop that will be executed ASAP
*/
setTimeout(() => {
console.log("timeout1");
}, 0);
function toto() {
Promise.resolve().then(() => {
console.log("promise2");
});
}
function titi() {
console.log(7);
}
Promise.resolve().then(() => {
console.log("promise1");
});
console.log(4);
toto();
console.log(5);
titi();
Promise.resolve().then(() => {
console.log("promise3");
});
console.log(6);
@PaulRosset
Copy link
Author

PaulRosset commented Sep 30, 2019

The exercise is to guess the order of each console.log
Response:

RESPONSES

  • 4
  • 5
  • 7
  • 6
  • Promise1
  • Promise2
  • Promise3
  • Timeout1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment