Skip to content

Lib.waitUntil method

Lib › waitUntil

Polls a predicate until it becomes truthy, or rejects once a bounded timeout elapses.

Integration-test evalInObsidian callbacks routinely need to wait for an asynchronous effect to settle (a view to open, a DOM node to appear, a setting to apply). Because the callback is serialized via toString() and cannot import modules, it can't reuse obsidian-dev-utils' retryWithTimeout / runWithTimeout. This helper is the shared, injected replacement for the per-closure poll loops consumers would otherwise hand-roll.

The predicate may be synchronous or asynchronous — it is awaited on every poll. It is checked immediately, then re-checked every intervalInMilliseconds until it returns truthy or timeoutInMilliseconds elapses, at which point the returned Promise rejects (the error includes message when provided).

Signature:

waitUntil(this: void, params: WaitUntilParams): Promise<void>

Parameters:

ParameterTypeDescription
thisvoid
paramsWaitUntilParamsThe predicate to poll plus optional timeout, interval, and timeout message.

Returns: Promise<void>A Promise that resolves once the predicate is truthy.