Skip to content

Instantly share code, notes, and snippets.

@aymericbouzy
Created August 25, 2021 12:53
Show Gist options
  • Save aymericbouzy/6cb7facbfa842e05cfa88798c03032de to your computer and use it in GitHub Desktop.
Save aymericbouzy/6cb7facbfa842e05cfa88798c03032de to your computer and use it in GitHub Desktop.
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