Last active
April 2, 2018 18:57
-
-
Save ball6847/e4e8e2c87b41f997ea72fe86285220b5 to your computer and use it in GitHub Desktop.
rxjs operator, make the data not emit too fast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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