Created
March 23, 2019 21:33
-
-
Save kosich/73877d92ddc6ca8e4a53af1e8effb688 to your computer and use it in GitHub Desktop.
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
| const { rxObserver } = require('api/v0.3'); | |
| const { Subject, interval, merge } = require('rxjs'); | |
| const { timeInterval, filter, distinctUntilChanged, map , pairwise } = require('rxjs/operators'); | |
| const START_EVENT = 'RUN'; | |
| const END_EVENT = 'END'; | |
| const events$ = new Subject(); | |
| const result$ = | |
| events$ | |
| .pipe( | |
| timeInterval(), | |
| pairwise(), | |
| filter(([first, second]) => | |
| first.value === START_EVENT | |
| && second.value === END_EVENT | |
| ), | |
| map(([, second]) => second.interval) | |
| ); | |
| events$.subscribe(rxObserver()); | |
| result$.subscribe(rxObserver()); | |
| // push events | |
| setTimeout(()=>{ | |
| events$.next(START_EVENT); | |
| }, 100); | |
| setTimeout(()=>{ | |
| events$.next(START_EVENT); | |
| }, 200); | |
| setTimeout(()=>{ | |
| events$.next(END_EVENT); | |
| }, 550); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run at https://observable-playground.github.io/gist/73877d92ddc6ca8e4a53af1e8effb688