system.reactive

Why isn't this code behaving asynchronous

依然范特西╮ 提交于 2019-12-10 23:51:43
问题 As I understand Subscribe method should be asynchronous whereas Run is synchronous. But this piece of code is working in synchronous manner. Can anybody fix it? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reactive.Linq; namespace RxExtensionsDemo { class Program { static void Main(string[] args) { IObservable<int> source = Observable.Generate<int, int>(0, i => i < 10000, i => i + 1, i => i * i); IDisposable subscription = source.Subscribe

How to build a rate-limiting API with Observables?

一世执手 提交于 2019-12-10 23:10:38
问题 I would like to create a simple Calculator service that has a single method to add numbers. This Add method should be async and has to limit the number of concurrent calls being made at a given time. For instance, no more than 5 concurrent calls per second. If the rate limit is exceeded, the call should throw an exception. The class should be like: public class RateLimitingCalculator { public async Task<int> Add(int a, int b) { //... } } Any ideas? I would like implement it with Reactive

What is the meaning of opening and closing boundaries with regard to operators such as Buffer?

房东的猫 提交于 2019-12-10 22:44:41
问题 I do not understand the overloads of the Buffer operator that require an opening or closing boundary. The overloads I am refering to are: public static IObservable<IList<TSource>> Buffer<TSource, TBufferClosing>(this IObservable<TSource> source, Func<IObservable<TBufferClosing>> bufferClosingSelector) public static IObservable<IList<TSource>> Buffer<TSource, TBufferBoundary>(this IObservable<TSource> source, IObservable<TBufferBoundary> bufferBoundaries) public static IObservable<IList

“Buffer until quiet” behavior from Reactive?

萝らか妹 提交于 2019-12-10 21:08:07
问题 My problem is sort of like the one the Nagle algorithm was created to solve, but not exactly. What I'd like is to buffer the OnNext notifications from an IObservable<T> into a sequence of IObservable<IList<T>> s like so: When the first T notification arrives, add it to a buffer and start a countdown If another T notification arrives before the countdown expires, add it to the buffer and restart the countdown Once the countdown expires (i.e. the producer has been silent for some length of time

Reactive subscription to event not followed by different event within a period of time

£可爱£侵袭症+ 提交于 2019-12-10 20:18:20
问题 I'm trying to figure out how to create a Reactive subscription for an event not followed by a different event within a specific time window. To illustrate, here's a use case: A busy indicator triggered by two events. Busy and NotBusy. They may fire close together but the indicator should not flash on/off too often. When NotBusy fires, there should be no indicator. When Busy fires and NotBusy hasn't fired within 5 seconds then it should display. Is there a way to do this entirely within

How to use Reactive UI to trigger a different action following a button click vs button press (hold)

不问归期 提交于 2019-12-10 19:57:00
问题 I'm trying to implement a UI control where the user can click a button to have a thing move by a little, or hold the button down and have the thing move while the button is held down. Let's say I have Task<Unit> StartMove() , Task<Unit> StopMove() and Task<Unit> MoveStep() . The button click should perform the MoveStep() and the button hold should start the move and then stop the move immediately when the button is released. Rapid clicks (double clicks) should be ignored while the move is

The difference between Rx Throttle(…).ObserveOn(scheduler) and Throttle(…, scheduler)

亡梦爱人 提交于 2019-12-10 19:54:29
问题 I have the following code: IDisposable subscription = myObservable.Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .Subscribe(_ => UpdateUi()); As expected, UpdateUi() will always execute on the main thread. When I change the code to IDisposable subscription = myObservable.Throttle(TimeSpan.FromMilliseconds(50)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => UpdateUi()); UpdateUI() will be executed in a background thread. Why is not Throttle(...).ObserveOn(scheduler)

Reactive Extensions SelectMany and Concat

ぐ巨炮叔叔 提交于 2019-12-10 17:51:44
问题 I understand that the behaviour of SelectMany is to effectively merge the results of each value produced into a single stream so the ordering in nondeterministic. How do I do something similar to concatAll in RxJs in C#. var obs = Observable.Range (1, 10).SelectMany (x => { return Observable.Interval (TimeSpan.FromSeconds(10 - x)).Take (3); }).Concat(); This is effectively what I want to do, Given a Range, Wait a bit for each then concat in the order that they started in. Obviously this is a

RX.Net : Use Retry but log any Exception

大城市里の小女人 提交于 2019-12-10 16:58:35
问题 I am new to RX and have been investigating error handling and the use of Retry; I have the following (yes I know it's not a 'real' unit test but it gives me place to fiddle!!) and was wondering how I go about keeping the Retry but be able to log any Exception? [Test] public void Test() { var scheduler = new TestScheduler(); var source = scheduler.CreateHotObservable( new Recorded<Notification<long>>(10000000, Notification.CreateOnNext(0L)), new Recorded<Notification<long>>(20000000,

Can I Pair Two Sequences Together by a Matching Key?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 14:57:43
问题 Let's say sequence one is going out to the web to retrieve the contents of sites 1, 2, 3, 4, 5 (but will return in unpredictable order). Sequence two is going to a database to retrieve context about these same records 1, 2, 3, 4, 5 (but for the purposes of this example will return in unpredictable order). Is there an Rx extension method that will combine these into one sequence when each matching pair is ready in both sequences ? Ie, if the first sequence returns in the order 4,2,3,5,1 and