Skip to content

Instantly share code, notes, and snippets.

@alex-okrushko
Last active August 2, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-okrushko/4d6c510534c75a53d856b252e87dc846 to your computer and use it in GitHub Desktop.
Save alex-okrushko/4d6c510534c75a53d856b252e87dc846 to your computer and use it in GitHub Desktop.
example of intervalBackoff that is reset on mousemove.
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