system.reactive

Making an IObservable<T> that uses async/await return completed tasks in original order

落爺英雄遲暮 提交于 2020-01-11 16:29:17
问题 Suppose you have a list of 100 urls and you want to download them, parse the response and push the results through an IObservable: public IObservable<ImageSource> GetImages(IEnumerable<string> urls) { return urls .ToObservable() .Select(async url => { var bytes = await this.DownloadImage(url); var image = await this.ParseImage(bytes); return image; }); } I have some problems with this. One is that it's bad etiquette to hammer a server with 100 requests at the same time -- ideally you would

Making an IObservable<T> that uses async/await return completed tasks in original order

送分小仙女□ 提交于 2020-01-11 16:28:10
问题 Suppose you have a list of 100 urls and you want to download them, parse the response and push the results through an IObservable: public IObservable<ImageSource> GetImages(IEnumerable<string> urls) { return urls .ToObservable() .Select(async url => { var bytes = await this.DownloadImage(url); var image = await this.ParseImage(bytes); return image; }); } I have some problems with this. One is that it's bad etiquette to hammer a server with 100 requests at the same time -- ideally you would

How to organize sequence of data processors with .net RX

筅森魡賤 提交于 2020-01-11 13:21:08
问题 What is the best way to organize sequence of data processors with .net RX? - a. Call methods on observable like observable.Do(log).Select(transformation).Do(work).Aggregate(someState)... - b. Implement custom observers, if so - how to chain them - c. Other option.. And also what is the best option to handle possible exceptions in observable itself (see my concerns above) and to handle exceptions inside Do, Select, etc (as I know the best practice is that Subscribers shouldn't throw). Also I

How to organize sequence of data processors with .net RX

喜欢而已 提交于 2020-01-11 13:21:04
问题 What is the best way to organize sequence of data processors with .net RX? - a. Call methods on observable like observable.Do(log).Select(transformation).Do(work).Aggregate(someState)... - b. Implement custom observers, if so - how to chain them - c. Other option.. And also what is the best option to handle possible exceptions in observable itself (see my concerns above) and to handle exceptions inside Do, Select, etc (as I know the best practice is that Subscribers shouldn't throw). Also I

How to extend Throttle Timespan in middle of a long running query?

泪湿孤枕 提交于 2020-01-11 10:29:10
问题 Is it possible to extend Throttle Timespan value in middle of a query? For instance, assuming an example as in 101 Rx Samples Throttle there is this query var throttled = observable.Throttle(TimeSpan.FromMilliseconds(750)); . What if I wanted to change it so that if during the first 500 ms there will be no events, then the throttling value would be extended to, e.g., 1500 ms for every event thereafter. Would this be a place to use the Switch operator? 回答1: There is an overload of Throttle

Wrapping rate limiting API call

人走茶凉 提交于 2020-01-10 05:10:28
问题 I have access an API call that accepts a maximum rate of calls per second . If the rate is exceeded, an exception is thrown . I would like to wrap this call into an abstraction that does the necessary to keep the call rate under the limit. It would act like a network router: handling multiple calls and returning the results to the correct caller caring about the call rate. The goal is to make the calling code as unaware as possible about that limitation. Otherwise, every part in the code

Generate numbers at random time intervals with rx

故事扮演 提交于 2020-01-09 05:33:25
问题 How can I generate a list of number with Rx.Net, like 0-100, where each number is generated at a random time? edit: seems like this works public void NonBlocking_event_driven() { var random = new Random(); var ob = Observable.Create<int>( observer => { timer.Interval = 1000; timer.Elapsed += (s, e) => observer.OnNext(random.Next(0, 3)); timer.Elapsed += OnTimerElapsed; timer.Start(); return Disposable.Empty; }); var subscription = ob.Subscribe(UserAction); Console.ReadLine(); subscription

How to avoid disposing SubscriberSocket

拈花ヽ惹草 提交于 2020-01-07 08:11:01
问题 This implementation is bad since it will end up disposing the SubscriberSocket when the first subscription terminates. When I run it, nothing seems to publish. [This uses Rx 3.0.0] How to modify Receive function to fix this problem? using System; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using NetMQ; using NetMQ.Sockets; using System.Reactive.Linq; namespace App1 { class MainClass { // publisher for testing, should be an external data publisher in

How to impelment dynamic time interval in Reactive Extension

ⅰ亾dé卋堺 提交于 2020-01-06 20:39:11
问题 I have a scenario where timer interval changes on every tick event. As shown in below code: Timer tmrObj = new Timer(); tmrObj.Interval = TimeSpan.FromSeconds(11); tmrObj.Tick += TimerTickHandler; public void TimerTickHandler(EventArg arg) { tmrObj.pause(); var response = MakeSomeServiceCall(); tmr.Interval = response.Interval; tmrObj.resume(); } If I need to implement Timers in Rx for the same. I can achieve using Timer function. But how can I manipulate Interval on event tick as shown in

Passing an IObservable to a constructor - good idea?

和自甴很熟 提交于 2020-01-06 16:19:18
问题 I read a comment on this web site about how to use IObservable that said.. As a general rule (guideline), I strongly suggest not having an IObservable<T> as a parameter to a method. The obvious caveat being if that method is a new Rx Operator e.g. Select , MySpecialBuffer , Debounce etc. So I've been trying to apply this advice to my code and keep running into situations where it seems convenient to break this rule. Take a look at the code below and compare PersonSelectorViewModelA and