Skip to content

Instantly share code, notes, and snippets.

Avatar

Aymeric Bouzy aymericbouzy

View GitHub Profile
View scenario-runner.js
// 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
View resumable saga.ts
new Saga()
.do(lockResource)
.withCompensatingAction(unlockResource)
.then(processPayment)
.withCompensatingAction(cancelPayment)
.then(addBillingItem);
View saga.ts
const compensatingActions = [];
try {
await lockResource();
compensatingActions.push(unlockResource);
const receipt = await processPayment();
compensatingActions.push(() => cancelPayment(receipt));
await addBillingItem();
View Retry success.md
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%
View medium-finally-5.js
let finalError
try {
throw "oups!";
} catch(error) {
throw "so clumsy...";
} catch(error) {
finalError = error
}
console.log("hello!");
if (finalError) {
View medium-finally-6.js
(function() {
try {
return "early";
} finally {
console.log("hello!");
}
})();
View medium-finally-8.js
try {
db.connect();
const data = db.getData();
return status(200).data(data);
} catch(error) {
return status(500).error(error);
} finally {
db.disconnect();
}
View medium-finally-7.js
(function() {
try {
throw "oups!";
} catch(error) {
return "early";
} finally {
console.log("hello!");
}
})();
View medium-finally-4.js
try {
throw "oups!";
} catch(error) {
throw "so clumsy...";
} finally {
console.log("hello!");
}
View medium-finally-3.js
try {
throw "oups!";
} finally {
console.log("hello!");
}