Skip to content

Instantly share code, notes, and snippets.

@aymericbouzy
Created August 25, 2021 12:53
Embed
What would you like to do?
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