rxjs / 7.5.5 / api / index / function / racewith.html /

raceWith

function stable operator

Creates an Observable that mirrors the first source Observable to emit a next, error or complete notification from the combination of the Observable to which the operator is applied and supplied Observables.

raceWith<T, A extends readonly, unknown>()

Parameters

There are no parameters.

Description

Example

import { interval, map, raceWith } from 'rxjs';

const obs1 = interval(7000).pipe(map(() => 'slow one'));
const obs2 = interval(3000).pipe(map(() => 'fast one'));
const obs3 = interval(5000).pipe(map(() => 'medium one'));

obs1
  .pipe(raceWith(obs2, obs3))
  .subscribe(winner => console.log(winner));

// Outputs
// a series of 'fast one'

© 2015–2022 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/function/raceWith