throttle

RxJS 5 throttle

by Brian Troncone

HTML

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

JavaScript

//emit value every 1 second
const source = Rx.Observable.interval(1000);
//incrementally increase the time to resolve based on source
const promise = val => new Promise(resolve => setTimeout(() => resolve(`Resolved: ${val}`), val * 100));
//when promise resolves emit item from source
const example = source
	.throttle(promise)
  .map(val => `Throttled off Promise: ${val}`);

const subscribe = example.subscribe(val => console.log(val));