Skip to content

Instantly share code, notes, and snippets.

Created August 25, 2021 12:53
What would you like to do?
const compensatingActions = [];
try {
await lockResource();
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