I have two promises that need to act as Transactions, if one of them fails, a "rollback" should occur.
For example: When I create a user I want to send a confirmation email, but what happens if there is an error on sending the email, the user will be created but will never get a confirmation.
await saveUser(user) await sendEmail(user)
If I switch the order, what happens when something goes wrong on creating the user? It will get a confirmation.
await sendEmail(user) await saveUser(user)
I thought a
Promise.all will do the trick, but it doesn’t.
await Promise.all([saveUser(user), sendEmail(user)]);