I am learning JS promises. I am kinda confused on how to reslove the promise returned by f2 only after running the cb function which takes 5 seconds.
var cb = function(){
console.log('5 sec');
}
var f2 = function(){
return new Promise((resolve,reject)=>{
setTimeout(cb, 5000);
console.log('Last line of f2')
resolve('5RESOLVED')
});
}
f2().then(res=>{
console.log(res)
})
The current output is in the following order
- Last line of f2
- 5RESOLVED
- 5 sec
I want the output to be - Last line of f2 - 5 sec -5Resolved