Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created May 3, 2021 09:14
Show Gist options
  • Save armanozak/26ed961235f238d0bfd10b39a1233a71 to your computer and use it in GitHub Desktop.
Save armanozak/26ed961235f238d0bfd10b39a1233a71 to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] RxJS 6 timeout #blog #rxjs
import { concat, partition, timer } from "rxjs";
import { first, share, timeout } from "rxjs/operators";
const count$ = timer(3000, 2000).pipe(share());
const [first$, rest$] = partition(count$, (_, index) => index === 0);
concat(
first$.pipe(
timeout(5000),
first()
),
rest$.pipe(timeout(1000))
).subscribe({ next: console.log, error: console.error });
// (after ~3s) 0
// (after ~1s) Error: Timeout has occurred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment