From ab5e67edb63f10521ea7a45176bba4bb58aef76b Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 29 Oct 2024 15:01:02 +0900 Subject: [PATCH] test(async): fix flakiness of throttle example --- async/unstable_throttle.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/async/unstable_throttle.ts b/async/unstable_throttle.ts index cc48ef2299bd..1fe448744f59 100644 --- a/async/unstable_throttle.ts +++ b/async/unstable_throttle.ts @@ -41,7 +41,11 @@ export interface ThrottledFunction> { * import { assert } from "@std/assert" * * let called = 0; - * await using server = Deno.serve({ port: 0, onListen:() => null }, () => new Response(`${called++}`)); + * const requestReceived = Promise.withResolvers(); + * await using server = Deno.serve({ port: 0 }, () => { + * requestReceived.resolve(); + * return new Response(`${called++}`) + * }); * * // A throttled function will be executed at most once during a specified ms timeframe * const timeframe = 100 @@ -51,6 +55,7 @@ export interface ThrottledFunction> { * } * * await retry(() => assert(!func.throttling)) + * await requestReceived.promise; * assert(called === 1) * assert(!Number.isNaN(func.lastExecution)) * ```