async function runClaimWorkflow(claim: SubmittedClaim, ctx: WorkflowContext) {
// non deterministic functions should be wrapped
let time = ctx.run(() => new Date())
let uuid = ctx.run(() => uuidv4())
console.log(`Time: ${time.epoch}; UUID: ${uuid}`)
// Also external calls should be wrapped
let isEligible = ctx.run(() => {
eligibilityService.isEligibile(claim)
let ctx = new WorkflowContext()
await runClaimWorkflow(claim, ctx)
await runClaimWorkflow(claim, ctx)
// Time: 116637383899; UUID=aee2233-...
// Time: 116637383899; UUID=aee2233-...
// inside the context (simplified),
// we have a history of the execution
private executionHistory = [
{ result: 116637383899 },
{ result: "aee2233-..." },
async run(callb: () => Any) {
if (this.currentIndex <= this.executionHistory.length) {
let result = this.executionHistory[this.currentIndex]
executionHistory.push({ result })