Skip to content

Instantly share code, notes, and snippets.

@ball6847
Last active April 2, 2018 18:57
Show Gist options
  • Select an option

  • Save ball6847/e4e8e2c87b41f997ea72fe86285220b5 to your computer and use it in GitHub Desktop.

Select an option

Save ball6847/e4e8e2c87b41f997ea72fe86285220b5 to your computer and use it in GitHub Desktop.
rxjs operator, make the data not emit too fast
import { timer } from 'rxjs/observable/timer';
import { delayWhen } from 'rxjs/operators';
export const delayThreshold = (threshold: number, start = Date.now()) =>
delayWhen(() => {
const delay = threshold - (Date.now() - start);
return timer(delay > 0 ? delay : 0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment