Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created May 3, 2021 09:18
Show Gist options
  • Save armanozak/f05ab0d75904a0875e988de7ba0c8594 to your computer and use it in GitHub Desktop.
Save armanozak/f05ab0d75904a0875e988de7ba0c8594 to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] RxJS 6 shareReplay #blog #rxjs
import { interval, of, zip } from "rxjs";
import { map, shareReplay } from "rxjs/operators";
const shared$ = zip(interval(1000), of("A", "B", "C", "D", "E")).pipe(
map(([, char]) => char),
shareReplay({ refCount: true, bufferSize: 3 })
);
shared$.subscribe(console.log);
// (~1s apart) A, B, C, D, E
setTimeout(() => shared$.subscribe(console.log), 6000);
// (after ~6s, all at once) C, D, E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment