/*
Description:
Here we use a chain of function with a "await" and one without "await",
When we have the "await" then we make the coments by the order of the lines,
but when the root function doesn't use the "await" then only this function lose the order of the
lines, but other function in the chain still will keep this order bexause they have the "await".
Note - when a functiion doens't return a Promise but an undefined then the "awaint" doesn't make
anything and all the calls goes by the lines orders, no matter with ior without "await"
*/
const sayHi = () => {
return new Promise(resolve => {
setTimeout(() => {
console.log('Say Hi');
resolve();
}, 2000);
});
}
/*
const sayHi = () => {
console.log('say Hi');
}
*/
const callSayHi = async () => {
console.log('Call Say Hi');
await sayHi();
console.log('Call Say Hi - finished');
}
const withAwait = async () => {
console.log('withAwait');
await callSayHi();
console.log('withAwait - finished');
}
const withoutAwait = () => {
console.log('withoutAwait');
callSayHi();
console.log('withoutAwait - finished');
}
// setTimeout(async () => {await withAwait();}, 0);
setTimeout(() => {withoutAwait();}, 0);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.