API Reference

wait-for-event

API entries in this module: 2

Overview

WaitForEvent helps you trigger an action and then wait for emissions from an Observable event property on a target object.

Configure count to wait for one or more emissions, timeout to cap how long it waits, and ignoreInitialValue when the first emission should be skipped.

The wait(trigger) call subscribes, runs the trigger (sync/Promise/Observable), collects emitted values, and resolves with the value (or values). If timeout is reached first, it resolves null.

Example: wait for emitted events

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

const target = {
  message$: new Subject<string>(),
};

const waiter = new WaitForEvent(target, 'message$', {
  count: 2,
  timeout: 1000,
  ignoreInitialValue: false,
});

const result = await waiter.wait(() => {
  target.message$.next('first');
  target.message$.next('second');
});

console.log(result); // ['first', 'second']