system.reactive

What is the best way to “rate limit” consuming of an Observable?

寵の児 提交于 2019-12-04 23:29:46
问题 I have a bunch of events coming in and I have to execute ALL of them without a loss, but I want to make sure that they are buffered and consumed at the appropriate time slots. Anyone have a solution? I can't find any operators in Rx that can do that without the loss of the events (Throttle - looses events). I've also considered Buffered, Delay, etc... Can't find a good solution. I've tried to put a timer in the middle, but somehow it doesn't work at all: GetInitSequence() .IntervalThrottle

What is the proper way to create an Observable which reads a stream to the end

北慕城南 提交于 2019-12-04 22:57:07
问题 I'm struggling here. Normally I'd read a book but there aren't any yet. I've found countless examples of various things to do with reading streams using RX but I'm finding it very hard to get my head around. I know I can use Observable.FromAsyncPattern to create a wrapper of the Stream's BeginRead/EndRead or BeginReadLine/EndReadLine methods. But this only reads once -- when the first observer subscribes. I want an Observable which will keep reading and pumping OnNext until the stream errors

What to do with IObservers being disposed?

♀尐吖头ヾ 提交于 2019-12-04 22:35:31
问题 I'm using Reactive Extensions for easy event handling in my ViewModels (Silverlight and/or Wp7 apps). For sake of simplicity let's say I have a line like this in the ctor of my VM: Observable.FromEvent<PropertyChangedEventArgs>( h => MyObject.PropertyChanged += h, h => MyObject.PropertyChanged -= h) .Where(e=>e.PropertyName == "Title") .Throttle(TimeSpan.FromSeconds(0.5)) .Subscribe(e=>{/*do something*/}); this returns an IDisposable object, which if disposed will unsubscribe. (Am I right in

Rx how to create a sequence from a pub/sub pattern

倾然丶 夕夏残阳落幕 提交于 2019-12-04 20:35:23
I'm trying to evaluate using Rx to create a sequence from a pub/sub pattern (i.e. classic observer pattern where next element is published by the producer(s)). This is basically the same as .net events, except we need to generalize it such that having an event is not a requirement, so I'm not able to take advantage of Observable.FromEvent. I've played around with Observable.Create and Observable.Generate and find myself end up having to write code to take care of the pub/sub (i.e. I have to write producer/consumer code to stash the published item, then consume it by calling IObserver.OnNext()

How to create an Rx (RxJS) stream that can be switched between single-item and batch-mode?

醉酒当歌 提交于 2019-12-04 20:21:41
I have an Rx stream that is an outgoing change feed from a particular component. Occasionally I want to be able to enter a batch mode on the stream so that items passed to onNext accumulate and are passed on only when the batch mode is exited. Normally I'll pass single items through the stream: stream.onNext(1); stream.onNext(2); There is a 1-to-1 mapping between the items passed to onNext and the items received in the subscribe , so the previous snippet results in two calls to subscribe with the the values 1 and 2. The batch mode I am looking for might work something like this: stream

How can I use Reactive Extensions to throttle Events using a max window size?

*爱你&永不变心* 提交于 2019-12-04 18:40:09
问题 Scenario : I am building a UI application that gets notifcations from a backend service every few milliseconds. Once I get a new notification i want to update the UI as soon as possible. As I can get lots of notifications within a short amount of time, and as I always only care about the latest event, I use the Throttle() method of the Reactive Extensions framework. This allows me to ignore notification events that are immediately followed by a new notification and so my UI stays responsive.

How do I change the Rx Builder implementation to fix the stack overflow exception?

让人想犯罪 __ 提交于 2019-12-04 17:59:31
问题 I'm trying to come up with an Rx Builder to use Reactive Extension within the F# Computation Expression syntax. How do I fix it so that it doesnt blow the stack? Like the Seq example below. And is there any plans to provide an implementation of the RxBuilder as part of the Reactive Extensions or as part of future versions of the .NET Framework ? open System open System.Linq open System.Reactive.Linq type rxBuilder() = member this.Delay f = Observable.Defer f member this.Combine (xs:

Unit testing with FromAsyncPattern

回眸只為那壹抹淺笑 提交于 2019-12-04 17:36:42
The Reactive Extensions have a sexy little hook to simplify calling async methods: var func = Observable.FromAsyncPattern<InType, OutType>( myWcfService.BeginDoStuff, myWcfService.EndDoStuff); func(inData).ObserveOnDispatcher().Subscribe(x => Foo(x)); I am using this in an WPF project, and it works great at runtime. Unfortunately, when trying to unit test methods that use this technique I am experiencing random failures. ~3 out of every five executions of a test that contain this code fails. Here is a sample test (implemented using a Rhino/unity auto-mocking container): [TestMethod()] public

Reactive Framework / DoubleClick

核能气质少年 提交于 2019-12-04 16:48:29
I know that there is an easy way to do this - but it has beaten me tonight ... I want to know if two events occur within 300 milliseconds of each other, as in a double click. Two leftdown mouse clicks in 300 milliseconds - I know this is what the reactive framework was built for - but damn if I can find a good doc that has simple examples for all the extenstion operatores - Throttle, BufferWithCount, BufferWithTime - all of which just werent' doing it for me.... The TimeInterval method will give you the time between values. public static IObservable<Unit> DoubleClicks<TSource>( this

Rx - How to create IObservable<T> from Task<T> such that unsubscribing cancels the task?

回眸只為那壹抹淺笑 提交于 2019-12-04 16:06:13
I'm new to Rx so bear with me. I want to wrap a Task<T> in an IObservable<T> . So far so good: Task<T> task = Task.Factory.StartNew(...); IObservable<T> obs = task.ToObservable(); Now, what I want is to signal the task to cancel when the observer unsubscribes: var cancel = new CancellationToken(); Task<T> task = Task.Factory.StartNew(..., cancel); IObservable<T> obs = task.ToObservable(); //there should be a way to tie the cancel token //to the IObservable (?) IDisposable disposable = obs.Subscribe(...); Thread.Sleep(1000); disposable.Dispose(); // this should signal the task to cancel How do