I have 3 promises and all have diffrent setimeouts when I am using async the first one is coming out on console after 4 second as expected.
But the second and third are coming just after that without time delays of 3s and 2s respectively.
What can I do here so that first comes at 4s, second 3s after the first and third 2s after the seconds.
Here is the js code
const ank = async() => {
let p1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("resolved first");
}, 2000);
})
let p2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("resolved second");
}, 3000);
})
let p3 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("resolved third");
}, 4000);
})
console.log("p3 started");
let a = await p3.then((value) => {
console.log(value)
}).catch((error) => {
console.lo(error);
});
console.log("p3 ended\n\n");
console.log("p2 started\n")
let b = await p2.then((value) => {
console.log(value);
}).catch((error) => {
console.log(error);
});
console.log("p2 ended\n\n\n");
console.log("p1 started\n")
let b1 = await p1.then((value) => {
console.log(value);
}).catch((error) => {
console.log(error);
});
console.log("p1 ended");
}
ank();