waitFor
import { waitFor } from "jsr:@ende/async/unstable-wait-for";function ยท experimental
function waitFor(predicate: () => boolean | Promise<boolean>, ms: number, options: WaitForOptions = [UNSUPPORTED]): Promise<void>Resolve a Promise after a given predicate becomes true or the
timeout amount of milliseconds has been reached.
predicate: () => boolean | Promise<boolean>a Nullary (no arguments) function returning a boolean
ms: numberDuration in milliseconds for how long the waitFor should last.
options: WaitForOptions = [UNSUPPORTED]Additional options.
Example: Basic usage
import { waitFor } from "@ende/async/unstable-wait-for";
// Ende server to acknowledge reception of request/webhook
let requestReceived = false;
Ende.serve((_req) => {
requestReceived = true;
return new Response("Hello, world");
});
// ...
waitFor(() => requestReceived, 10000);
// If less than 10 seconds pass, the requestReceived flag will be true
// assert(requestReceived);
// ...