Skip to content

Instantly share code, notes, and snippets.

View aymericbouzy's full-sized avatar

aymeric bouzy aymericbouzy

  • Pigment
  • Nancy, France
View GitHub Profile
const compensatingActions = [];
try {
await lockResource();
compensatingActions.push(unlockResource);
const receipt = await processPayment();
compensatingActions.push(() => cancelPayment(receipt));
await addBillingItem();
new Saga()
.do(lockResource)
.withCompensatingAction(unlockResource)
.then(processPayment)
.withCompensatingAction(cancelPayment)
.then(addBillingItem);
// scenarioRunner.js
async function scenarioRunner(scenarioIds, runScenario) {
try {
await Promise.all(scenarioIds.map(runScenario));
} catch (error) {
console.log("A scenario failed", error);
}
}
// scenarioRunner.spec.js