Can someone explain why in this scenario the results are different? I mean, in the last block the second call does wait for the 'setTimeOut'. Can't I pass the parameter as I did?
function awaitFor(seconds = 2000) {
return new Promise(function (resolve) {
setTimeout(() => resolve(), seconds)
})
}
/** Why this */
awaitFor(2000)
.then(() => console.log('Executing promise 1'))
.then(() => awaitFor(2000))
.then(() => console.log('Executing promise 2'))
awaitFor(2000)
.then(() => console.log('Executing promise 1'))
.then(awaitFor)
.then(() => console.log('Executing promise 2'))
/** Is different than this? */
awaitFor(2000)
.then(() => console.log('Executing promise 1'))
.then(awaitFor(2000))
.then(() => console.log('Executing promise 2'))