⬅️ Execute Program JavaScript Concurrency
Promise constructor is synchronous
- When we do
new Promise(...)and pass a callback to the constructor, that cb is ran immediately (even if you wrapped with asetTimeout)
const array = [];
array.push('before');
new Promise(resolve => {
array.push('constructed');
});
array.push('after');
array;
// Result:
['before', 'constructed', 'after']- but
thenalways works async - 💡 Constructor callbacks always run immediately and synchronously, while
thencallbacks are scheduled to run asynchronously.