system.reactive

What's the Rx.NET equivalent to flatMapIterable?

◇◆丶佛笑我妖孽 提交于 2020-12-13 03:43:15
问题 Today I finally stumbled upon the solution of a really trivial RX problem: Suppose you have an Observable which returns Lists of items. Like Observable<List<String>> . You often receive something like this as responses from web APIs. However chances are you want to operate on the single items, in this case the Strings. flatMapIterable to the rescue! This handy operator flattens a stream of Iterables into a stream generated from the single items of these Iterables by means of a mapping

Dispose of Observable Items as they are generated

ぐ巨炮叔叔 提交于 2020-12-08 06:03:35
问题 I have an IObservable that generates items that are disposable, and it will generate a potentially infinite number of them over its lifetime. Because of this, I want to dispose of the last item each time a new item is generated, so the Using operator will not work for this. Is there a different Rx.NET operator that can accomplish this function? 回答1: If you have a IObservable<IDisposable> source then do this to automatically dispose of the previous value and to clean up when the sequence ends:

Dispose of Observable Items as they are generated

隐身守侯 提交于 2020-12-08 06:00:10
问题 I have an IObservable that generates items that are disposable, and it will generate a potentially infinite number of them over its lifetime. Because of this, I want to dispose of the last item each time a new item is generated, so the Using operator will not work for this. Is there a different Rx.NET operator that can accomplish this function? 回答1: If you have a IObservable<IDisposable> source then do this to automatically dispose of the previous value and to clean up when the sequence ends:

Create observable from periodic async request

扶醉桌前 提交于 2020-12-03 06:35:27
问题 I want a generic way to convert an asynchronous method to an observable. In my case, I'm dealing with methods that uses HttpClient to fetch data from an API. Let's say we have the method Task<string> GetSomeData() that needs to become a single Observable<string> where the values is generated as a combination of: Repeated periodic calls to GetSomeData() (for example every x seconds) Manually triggered calls to GetSomeData() at any given time (for example when user hits refresh). Since there is

Create observable from periodic async request

早过忘川 提交于 2020-12-03 06:34:50
问题 I want a generic way to convert an asynchronous method to an observable. In my case, I'm dealing with methods that uses HttpClient to fetch data from an API. Let's say we have the method Task<string> GetSomeData() that needs to become a single Observable<string> where the values is generated as a combination of: Repeated periodic calls to GetSomeData() (for example every x seconds) Manually triggered calls to GetSomeData() at any given time (for example when user hits refresh). Since there is