Skip to content

API Reference


API Reference / @dasch-ng/rxjs-operators / pollUntil

Function: pollUntil() ​

pollUntil<T>(read, options?): Observable<NonNullable<T>>

Defined in: poll-until.ts:32

Reads a value repeatedly until it is ready, then emits it once and completes. The first read happens immediately, so an already available value is emitted synchronously.

Useful when something is initialised outside your control, e.g. an auth token or a third-party script global, and requests must wait for it.

Type Parameters ​

T ​

T

Parameters ​

read ​

() => T

options? ​

PollUntilOptions<T> = {}

Returns ​

Observable<NonNullable<T>>

Example ​

typescript
import { pollUntil } from '@dasch-ng/rxjs-operators';

pollUntil(() => auth.token, { timeout: 5000 })
  .pipe(switchMap((token) => http.get(url, { headers: { Authorization: `Bearer ${token}` } })))
  .subscribe();

pollUntil(() => window.someSdk, { interval: 250 }).subscribe((sdk) => sdk.init());

Released under the MIT License.