I'm trying to return a promise inside another by nesting two resolve
functions as follows:
const a = new Promise((resolve1, reject1) => {
resolve1(new Promise((resolve2, reject2) => {
setTimeout(() => resolve2('finished'), 6000)
}).catch((err) => reject1(1)));
});
The result of the operations await a
is finished
instead of Promise {'finished', ...}
After that I also tried using chaining
const a = new Promise((resolve, reject) => resolve('finished'))
.then((phrase) => {
return new Promise((resolve, reject) => resolve(phrase))
});
Unfortunately, I got the same result as in the previous attempt. Why is it wrong to do it either way? What would be the correct way to do this without using extra class definitions?