Correct me if I am wrong but I think this piece of code:
constcreatedPromise=newPromise((resolve,reject)=>{somePreviousPromise.then(result=>{// do something with the resultresolve(result);}).catch(reject);});
Could be simplyfied by avoiding the external creation of the wrapping Promise:
constcreatedPromise=somePreviousPromise.then((result)=>{// do something with the resultreturnresult;});});
Because returning the result will resolve the Promise chain, and the rejection will be forwarded.
Hey, you are absolutely correct. Wrapping promise into a promise is presented as an antipattern here. I will update an article to make that more clear!
Thanks!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Correct me if I am wrong but I think this piece of code:
Could be simplyfied by avoiding the external creation of the wrapping Promise:
Because returning the result will resolve the Promise chain, and the rejection will be forwarded.
Hey, you are absolutely correct. Wrapping promise into a promise is presented as an antipattern here. I will update an article to make that more clear!
Thanks!