Basically what you see me doing here is “asyncing” a promise that I’m just creating.
Is that some unadvisable, anti-pattern, fatal flow, or silly way to write a promise? If so, why?
function returnSomething(name) {
return new Promise(async (resolve, reject) => {
try {
//some dealings....
const somethingElse = await returnSomethingElse();
//do some stuff with 'somethingElse'
resolve(somethingElse);
} catch(error) {
//some dealings....
reject(error);
return;
}
});
}
The temptation to do this is basically very easy to explain. I want to avoid the .then().then().then() hell if I return a promise as a result from a promise.
I also wanted to avoid working with something like this:
function returnSomething(name) {
return new Promise((resolve, reject) => {
//some dealings....
returnSomethingElse().then((somethingElse) => {
//do some stuff with 'somethingElse'
resolve(somethingElse);
}).error((error) => {
//some dealings....
reject(error);
return;
});
}
});
}
Thanks in advance.