API Reference

WaitForEventclass

Utility class for async flows/tests where you trigger logic and wait for one or more Observable event emissions.

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.

Quick facts
Kind
class
Base class
keyof TTarget, TValue, >
Members
2
Package
@rs-x/core

Import

import { WaitForEvent } from '@rs-x/core';

Example

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']

Members

2 members in this class.

constructor
constructorpublic
constructor(
  private readonly _target: TTarget,
  private readonly _eventName: TEventName,
  options?: IWaitForEventOptions<TTarget, TEventName, TValue>
)

Parameters

Name
Type
Required
_target
TTarget
required
_eventName
TEventName
required
options?
IWaitForEventOptions<TTarget, TEventName, TValue>
optional
wait
methodpublic
public wait( trigger: () => void | Promise<unknown> | Observable<unknown>): Promise<TValue | null>

Parameters

Name
Type
Required
trigger
()
required

Returns

Promise<TValue | null>