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
import { defer, from } from "rxjs"; | |
import { retry, tap } from "rxjs/operators"; | |
const values = ["_", 0, 1, 0, 2, 0, 3, 0, 0, 0, 4]; | |
defer(() => { | |
values.shift(); | |
return from(values); | |
}) | |
.pipe( |
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
import { timer } from "rxjs"; | |
import { timeout } from "rxjs/operators"; | |
timer(5000, 1000) | |
.pipe(timeout({ first: 2000, with: _ => of("timeout") })) | |
.subscribe(console.log); | |
// (after ~2s) timeout |
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
import { timer } from "rxjs"; | |
import { timeoutWith } from "rxjs/operators"; | |
timer(5000, 1000) | |
.pipe(timeoutWith(2000, of("timeout"))) | |
.subscribe(console.log); | |
// (after ~2s) timeout |
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
import { timer } from "rxjs"; | |
import { timeout } from "rxjs/operators"; | |
const count$ = timer(3000, 2000); | |
count$ | |
.pipe(timeout({ first: 5000, each: 1000 })) | |
.subscribe({ next: console.log, error: console.error }); | |
// (after ~3s) 0 | |
// (after ~1s) Error: Timeout has occurred |
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
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), |
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
import { interval } from "rxjs"; | |
import { concatWith, map } from "rxjs/operators"; | |
const count1To5$ = interval(1000).pipe( | |
take(5), | |
map(i => i + 1) | |
); | |
const count6To9$ = interval(1000).pipe( | |
take(4), |
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
import { interval } from "rxjs"; | |
import { concat, map } from "rxjs/operators"; | |
const count1To5$ = interval(1000).pipe( | |
take(5), | |
map(i => i + 1) | |
); | |
const count6To9$ = interval(1000).pipe( | |
take(4), |
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
import { interval } from "rxjs"; | |
import { map, raceWith } from "rxjs/operators"; | |
const count1To5$ = interval(1000).pipe( | |
take(5), | |
map(i => i + 1) | |
); | |
const count6To9$ = interval(1000).pipe( | |
take(4), |
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
import { interval } from "rxjs"; | |
import { map, race } from "rxjs/operators"; | |
const count1To5$ = interval(1000).pipe( | |
take(5), | |
map(i => i + 1) | |
); | |
const count6To9$ = interval(1000).pipe( | |
take(4), |
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
import { interval } from "rxjs"; | |
import { map, zipWith } from "rxjs/operators"; | |
const count1To5$ = interval(1000).pipe( | |
take(5), | |
map(i => i + 1) | |
); | |
const count6To9$ = interval(1000).pipe( | |
take(4), |