How does FirstAsync work?

In my eternal desire to suck less, I try to understand the syntax of Rx.net FirstAsync(). Most of the documents are obsolete. First()
If I understand correctly, this allows me to start the stream as soon as the first element from the stream appears.

Let's say I have a thread myStream, and I want to start a thread that takes the first element and starts the thread based on this one element. In my case, it will be a stream of one.
I expect him to do this:

--- 1-2->
--- --->

How can i do this?

myStream.FirstAsync().Return(() => return "A"); // doesn't compile
+4
source share
2 answers

, : .FirstAsync() a Task ( .Result). Task, IObservable<TSource>. , .

, : myStream.FirstAsync().Select(_ => "A").

myStream.Take(1).Select(_ => "A"). FirstAsync , FirstAsync , myStream - . Take(1) .

+4

" FirstAsync?":

IObservable<T>, :

  • ( ), .

  • , , ( OnError), Catch Subscribe ..

, , FirstOrDefaultAsync

0

Source: https://habr.com/ru/post/1678964/


All Articles