Skip to content

Instantly share code, notes, and snippets.

@fzn0x
Created August 15, 2024 19:26
Show Gist options
  • Save fzn0x/b2b9e24557af86e683f3c5376220ae04 to your computer and use it in GitHub Desktop.
Save fzn0x/b2b9e24557af86e683f3c5376220ae04 to your computer and use it in GitHub Desktop.
After Synchronous Loop inside the Event Loop
const afterSynchronousLoop =
queueMicrotask ||
setImmediate ||
(function () {
if (Promise) {
return function (fn) {
Promise.resolve().then(fn);
};
}
return function (fn) {
setTimeout(fn, 0);
};
})();
afterSynchronousLoop(() => console.log("Hello, World!"));
console.log("Goodbye, World!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment