exhaustMap

RxJS 5 exhaustMap

HTML

<script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.umd.js"></script>

JavaScript

console.clear();

const firstInterval = Rx.Observable.interval(1000).take(10);
const secondInterval = Rx.Observable.interval(1000).take(2);

const exhaustSub = firstInterval.exhaustMap(f => {
	console.log(`Emission of first interval: ${f}`);
	return secondInterval;
}).subscribe(s => console.log(s));

/*
	I placed the first console.log so we could get a glimpse to what's happening behind the scene.
	When we subscribeds to the first interval, it starts to emit a value (value 0).
  This value is mapped to the second interval which then begins to emit (value 0).
  While the second intervals emit, values from the first interval are being ignored at this time.
  We can see this when firstInterval gives us our next value number 3 and not 1.
  
  Our output looks like this:
  Emission of first interval: 0
	0
  1
  Emission of first interval: 3
  0
	1
  Emission of first interval: 6
  0
  1
  Emission of first interval: 9
  0
  1
*/