When to use
Configure count to wait for multiple emissions, timeout to stop waiting after a max duration, and ignoreInitialValue when the first emission is just current state.
API Reference
Utility class for async flows/tests where you trigger logic and wait for one or more Observable event emissions.
Configure count to wait for multiple emissions, timeout to stop waiting after a max duration, and ignoreInitialValue when the first emission is just current state.
import { WaitForEvent } from '@rs-x/core';import { Subject } from 'rxjs';
import { WaitForEvent, type IWaitForEventOptions } from '@rs-x/core';
const target = {
message$: new Subject<string>(),
};
const options: IWaitForEventOptions<typeof target, 'message$', string> = {
count: 2,
timeout: 1000,
};
const waiter = new WaitForEvent(target, 'message$', options);
const result = await waiter.wait(() => {
target.message$.next('first');
target.message$.next('second');
});
console.log(result); // ['first', 'second']2 members in this class.
constructor(
private readonly _target: TTarget,
private readonly _eventName: TEventName,
options?: IWaitForEventOptions<TTarget, TEventName, TValue>
)Parameters
public wait( trigger: () => void | Promise<unknown> | Observable<unknown>): Promise<TValue | null>Parameters
Returns
Promise<TValue | null>