I spent whole day trying to figure out weather I use Promises wrongly.
Is that anti-pattern ?
export const myExample = (payload) => {
return new Promise((resolve, reject) => {})
}
Can I use async in promise like that ?
export const myExample = (payload) => {
return new Promise(async (resolve, reject) => {})
}
Also is that wrong as well ? Assuming adding async makes it a promise by default,
export const myExample = async (payload) => {
return new Promise((resolve, reject) => {})
}
also if that's the case, should I just return from function which will be same as resolve, and if I throw Error will be reject, so it would look like that ?
export const myExample = async (payload) => {
if(payload) return true
else throw new Error('Promise rejection?')
}
So is first and last the same ?