Skip to content

Instantly share code, notes, and snippets.

@kosich
Last active February 19, 2019 18:28
Show Gist options
  • Save kosich/1d6bb94e2122d75fbbc51a52aafa50c7 to your computer and use it in GitHub Desktop.
Save kosich/1d6bb94e2122d75fbbc51a52aafa50c7 to your computer and use it in GitHub Desktop.
Pausable Observable that accumulates values. Run at https://observable-playground.github.io/gist/1d6bb94e2122d75fbbc51a52aafa50c7
creates a stream that will not emit values until trigger$ emits.
then all events from the source$ are emited at once and continue
emiting on a normal schedule
source$ --0--1---2--------3--4--
trigger$ -----------o------------
0
result$ -----------1-----3--4---
2
const { rxObserver } = require('api/v0.3');
const { Observable, Subject, BehaviorSubject } = require('rxjs/Rx');
const trigger$ = Observable.of('o').delay(10);
const source$ = Observable.interval(3).take(5);
const afterTrigger$ = source$.skipUntil(trigger$);
const result$ =
source$
.buffer(trigger$)
.take(1)
.switchMap(x=>Observable.from(x))
.merge(afterTrigger$);
source$.subscribe(rxObserver('source$'));
trigger$.subscribe(rxObserver('trigger$'));
result$.subscribe(rxObserver('result$'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment