Last active
August 2, 2018 16:07
-
-
Save alex-okrushko/4d6c510534c75a53d856b252e87dc846 to your computer and use it in GitHub Desktop.
example of intervalBackoff that is reset on mousemove.
This file contains 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 {fromEvent} from 'rxjs'; | |
import {sampleTime, startWith, switchMap} from 'rxjs/operators'; | |
import {intervalBackoff} from 'backoff-rxjs'; | |
import {service} from './service'; | |
const newData$ = fromEvent(document, 'mousemove').pipe( | |
// There could be many mousemoves, we'd want to sample only | |
// with certain frequency | |
sampleTime(1000), | |
// Start immediately | |
startWith(null), | |
// Resetting exponential interval operator | |
switchMap(() => intervalBackoff(1000)), | |
switchMap(() => service.getData()), | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment