Advance promise example
chain promise eample
by Rijo R
HTML
<h4>
Cleen the room then if it is clened remove garbage then will get an ice creem.
</h4>
<h5>
</h5>
If all the codition satisfied u will get an ice cream
</h5>
<h6>
Output on console
</h6>
JavaScript
let cleanRoom = ()=>{ // function cleen the room return a promise it is resolved
return new Promise((resolve, reject)=>{
resolve('Clened the room');
})
}
let removeGarbage = (msg)=> { // function remove garbage then return a promise it is resolved
return new Promise((resolve, reject)=> {
resolve(msg + ' Garbage Removed');
})
}
let wonIceCream = (msg)=> { // function won ice creem then return a promise it is resolved
return new Promise((resolve, reject)=>{
resolve(msg + ' Won the ice cream');
})
}
cleanRoom() // CAll the function and pas message to next function
.then((resolve_clean)=>{
return removeGarbage(resolve_clean);
})
.then((_resolveGarbage)=>{
return wonIceCream(_resolveGarbage);
})
.then((_resolve_wonIce)=>{
console.log('Finished')
console.log(_resolve_wonIce);
})
.catch(()=>{
})