Skip to content

Instantly share code, notes, and snippets.

View aymericbouzy's full-sized avatar

aymeric bouzy aymericbouzy

  • Pigment
  • Nancy, France
View GitHub Profile
// 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
new Saga()
.do(lockResource)
.withCompensatingAction(unlockResource)
.then(processPayment)
.withCompensatingAction(cancelPayment)
.then(addBillingItem);
const compensatingActions = [];
try {
await lockResource();
compensatingActions.push(unlockResource);
const receipt = await processPayment();
compensatingActions.push(() => cancelPayment(receipt));
await addBillingItem();
Outcome percentage
Succeeds on 1st retry 76.3%
Succeeds on 2nd retry 2.8%
Succeeds on 3rd retry 1.3%
Succeeds on 4th retry 1.0%
Succeeds on 5th retry 1.0%
Dead-letter 17.6%
let finalError
try {
throw "oups!";
} catch(error) {
throw "so clumsy...";
} catch(error) {
finalError = error
}
console.log("hello!");
if (finalError) {
try {
db.connect();
const data = db.getData();
return status(200).data(data);
} catch(error) {
return status(500).error(error);
} finally {
db.disconnect();
}
(function() {
try {
throw "oups!";
} catch(error) {
return "early";
} finally {
console.log("hello!");
}
})();
(function() {
try {
return "early";
} finally {
console.log("hello!");
}
})();
try {
throw "oups!";
} catch(error) {
throw "so clumsy...";
} finally {
console.log("hello!");
}
try {
throw "oups!";
} finally {
console.log("hello!");
}