4 ms·
> In JavaScript, this is often indicated by new Promise inside a .then(). I have found myself doing this sometimes, why is it considered bad practice?
by r4mbini 7y ago
> In JavaScript, this is often indicated by new Promise inside a .then().
I have found myself doing this sometimes, why is it considered bad practice?
- kevsim 7y agoI guess because inside of a then() you can simply return the success case and throw the error case, no need to create a new Promise and call the resolve/reject functions.
- r4mbini 7y agoAh ok, they’re saying don’t use a new promise to do async logic not don’t use them for more sync things later down the chain. Thank you!
- rounce 7y agoWas trying to think of exceptions to this when I read and and could only think of one: When you need to wrap a callback API with unusual callback arguments, where a `promisify` like helper won't work. Then again, I still feel the wrapping function should be defined outside of the `then`, as it feels like this is a separate utility to the work being done in the Promise chain.
- r4mbini 7y agoThis is the context I’ve used it in