nicowernli
3/23/2018 - 11:53 AM

Medium switchMap

Medium switchMap

const Rx = require('rxjs');

const long$ = Rx.Observable.interval(1000).take(4);
const short$ = Rx.Observable.interval(500).take(4);

long$
  .switchMap(long => short$.map(short => console.log({ long, short })))
  .subscribe();
  
/** Output
{ long: 0, short: 0 }
{ long: 1, short: 0 }
{ long: 2, short: 0 }
{ long: 3, short: 0 }
{ long: 3, short: 1 }
{ long: 3, short: 2 }
{ long: 3, short: 3 }
*/