Created
May 3, 2021 08:52
-
-
Save armanozak/fb08eae62ddf7e06cea1151b55319c0d to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] RxJS 7 firstValueFrom and lastValueFrom #blog #rxjs
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, firstValueFrom, lastValueFrom } from "rxjs"; | |
import { map, take } from "rxjs/operators"; | |
const count1To5$ = interval(1000).pipe( | |
take(5), | |
map(i => i + 1) | |
); | |
firstValueFrom(count1To5$).then(console.log); | |
// (after ~1s) 1 | |
lastValueFrom(count1To5$).then(console.log); | |
// (after ~5s) 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment