BehaviorSubject.First () is deprecated, what is the alternative?

So, I have BehaviorSubject<string>one that I want to use for a property. I used the lock method First()to get the current value, which BehaviorSubjectis stored in the getter property.

The operation is First()now outdated, and what is the new way to achieve it?

+3
source share
2 answers

With BehaviorSubject<T>guaranteed you get a * value Firstthat is always available.

However, query operators IObservable<T>cannot work on this assumption as a whole, so an attribute Obsoletewas added to encourage people to use asynchronous methods, such as FirstAsync- helping them to "get into the pit of success."

- BehaviorSubject<T>, , safe Value. , , - :

var subject = new BehaviorSubject<string>("Some value");

:

var current = subject.Value;

* BehaviorSubject<T> , Dispose, Value , FirstAsync, ObjectDisposedException.

+6

, , First, IObservable. Value, , BehaviorSubject.

// synchronously wait for the value
var value = someObservable.FirstAsync().Wait();

// async await
var value = await someObservable.FirstAsync();
+7

All Articles