Promise example
All | ALL SETTLED | ANY | RACE
by Sunny SM
JavaScript
const getName = new Promise((resolve) => setTimeout(function() {
resolve('Sunny Attwal')
}), 1000);
const getLocation = new Promise((resolve) => setTimeout(function() {
resolve('Chandigarh')
}), 500);
const getProfile = new Promise((resolve, reject) => setTimeout(function() {
reject('Error in profile')
}), 200);
Promise.race([
getProfile,
getName,
getLocation
]
).then((res) => {
console.log('RESUT', res);
}).finally(() => {
console.log('All executions has done!');
})