'Rxjs toPromise() deprecated
I have read that toPromise() is being deprecated in RxJS 7 and will be removed in RxJS 8.
I have often used it with async await syntax in angular to handle http calls. Is it considered an anti pattern?
I understand the concept of streams but an http call only emit a single value. I don't get the point of observable for a simple http call. What should I use next? should I fully embrace reactive programming?
Solution 1:[1]
firstValueFrom and lastValueFrom is definitly a better alternative for many reasons:
- The naming is more readable and self explanatory.
- The additional ability to select either first or last value.
- The additional ability to declare a default value in case the observable didn't emit any value at all like so
await lastValueFrom(data$, {defaultValue: 'Some default value'})
For more about this checkout the video below:
https://www.youtube.com/watch?v=3aeK5SfWBSU
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tariq Saeed |
