Skip to content

Commit

Permalink
test(async): fix flakiness of throttle example (#6156)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Oct 29, 2024
1 parent b6ab0f4 commit 24cd7cf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion async/unstable_throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export interface ThrottledFunction<T extends Array<unknown>> {
* import { assert } from "@std/assert"
*
* let called = 0;
* await using server = Deno.serve({ port: 0, onListen:() => null }, () => new Response(`${called++}`));
* const requestReceived = Promise.withResolvers<void>();
* 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
Expand All @@ -51,6 +55,7 @@ export interface ThrottledFunction<T extends Array<unknown>> {
* }
*
* await retry(() => assert(!func.throttling))
* await requestReceived.promise;
* assert(called === 1)
* assert(!Number.isNaN(func.lastExecution))
* ```
Expand Down

0 comments on commit 24cd7cf

Please sign in to comment.