Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.

Latest commit

 

History

History
40 lines (28 loc) · 9.26 KB

File metadata and controls

40 lines (28 loc) · 9.26 KB

raceWithNotifications or raceN

function raceWithNotifications<GObservables extends IGenericRaceInObservables>(
  observables: GObservables,
): IObservable<IRaceObservableNotifications<GObservables>>

raceWithNotifications will wait for the first observable to complete (complete Notification) and then it will emit the last value received through the next Notifications of this observable. Finally, it will complete (complete Notification).

It is somehow equivalent of a Promise.race.

Diagram

Examples

Example 1

const observable1$ = mergeMapS$$(timeout(500), () => singleN<'a1'>('a1'));
const observable2$ = mergeMapS$$(timeout(1000), () => singleN<'a2'>('a2'));

const subscribe = raceWithNotifications([observable1$, observable2$]);

subscribe((value: IDefaultNotificationsUnion<'a1' | 'a2'>) => {
  console.log(value);
});

Output:

// 500ms
'next', 'a1'
'complete', undefined