waitFor.d.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { ActorRef, EmittedFrom } from '.';
  2. interface WaitForOptions {
  3. /**
  4. * How long to wait before rejecting, if no emitted
  5. * state satisfies the predicate.
  6. *
  7. * @default 10_000 (10 seconds)
  8. */
  9. timeout: number;
  10. }
  11. /**
  12. * Subscribes to an actor ref and waits for its emitted value to satisfy
  13. * a predicate, and then resolves with that value.
  14. * Will throw if the desired state is not reached after a timeout
  15. * (defaults to 10 seconds).
  16. *
  17. * @example
  18. * ```js
  19. * const state = await waitFor(someService, state => {
  20. * return state.hasTag('loaded');
  21. * });
  22. *
  23. * state.hasTag('loaded'); // true
  24. * ```
  25. *
  26. * @param actorRef The actor ref to subscribe to
  27. * @param predicate Determines if a value matches the condition to wait for
  28. * @param options
  29. * @returns A promise that eventually resolves to the emitted value
  30. * that matches the condition
  31. */
  32. export declare function waitFor<TActorRef extends ActorRef<any, any>>(actorRef: TActorRef, predicate: (emitted: EmittedFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<EmittedFrom<TActorRef>>;
  33. export {};
  34. //# sourceMappingURL=waitFor.d.ts.map