Skip to main content

waitFor()

function waitFor(condition: () => boolean, options: WaitForOptions): Promise<void>;

Defined in: src/lib/utils.ts:76

Wait for a condition to become true with timeout.

Polls the condition function until it returns true, or throws an error if the timeout is exceeded.

Parameters

ParameterTypeDescription
condition() => booleanFunction that returns true when the wait should end.
optionsWaitForOptionsConfiguration options.

Returns

Promise<void>

A promise that resolves when the condition is met.

Throws

Error if the timeout is exceeded.

Example

// Wait for model to load
await waitFor(() => HasModelLoaded(modelHash), {
  timeout: 5000,
  timeoutMessage: "Model failed to load"
});
 
// Wait with custom interval
await waitFor(() => someCondition(), { interval: 100 });