Created
August 25, 2021 12:53
-
-
Save aymericbouzy/6cb7facbfa842e05cfa88798c03032de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compensatingActions = []; | |
try { | |
await lockResource(); | |
compensatingActions.push(unlockResource); | |
const receipt = await processPayment(); | |
compensatingActions.push(() => cancelPayment(receipt)); | |
await addBillingItem(); | |
} catch (error) { | |
for (const compensatingAction of compensatingActions.reverse()) { | |
await compensatingAction(); | |
} | |
throw error; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment