diff --git a/examples/ci/app/test-routes/sleepWithoutAwait/route.ts b/examples/ci/app/test-routes/sleepWithoutAwait/route.ts index 171b9b6..791c95f 100644 --- a/examples/ci/app/test-routes/sleepWithoutAwait/route.ts +++ b/examples/ci/app/test-routes/sleepWithoutAwait/route.ts @@ -12,20 +12,20 @@ type Invoice = { type Charge = { invoice: Invoice; success: boolean; + counter: number }; const header = `test-header-foo` const headerValue = `header-bar` const payload: Invoice = { date: 123, email: "my@mail.com", amount: 10 } -let counter = 0; -const attemptCharge = () => { +const attemptCharge = (counter: number) => { counter += 1; if (counter === 3) { counter = 0; - return true; + return { success: true, counter }; } - return false; + return { success: false, counter }; }; export const { POST, GET } = testServe( @@ -36,13 +36,19 @@ export const { POST, GET } = testServe( expect(typeof invoice, typeof payload); expect(JSON.stringify(invoice), JSON.stringify(payload)); + let charge: Charge = { + success: false, + counter: 0, + invoice + } + for (let index = 0; index < 3; index++) { - const charge = await context.run("attemptCharge", () => { - const success = attemptCharge(); - const charge: Charge = { invoice, success }; - return charge; + charge = await context.run("attemptCharge", () => { + const { success, counter } = attemptCharge(charge.counter); + const newCharge: Charge = { invoice, success, counter }; + return newCharge; }); - + if (charge.success) { const [updateDb, receipt, sleepResult] = await Promise.all([ context.run("updateDb", () => { @@ -82,4 +88,4 @@ export const { POST, GET } = testServe( [ header ]: headerValue } } -) \ No newline at end of file +)