system.reactive

Reactive Framework (RX) and dealing with events Asynchronously

穿精又带淫゛_ 提交于 2019-12-06 01:02:03
So I'm just playing around with RX and learning it. I started playing with Events, and wanted to know how to subscribe to events, and process the results in batches asynchronously. Allow me to explain with code: Simple class that raises events: public class EventRaisingClass { public event EventHandler<SomeEventArgs> EventOccured; //some other code that raises event... } public class SomeEventArgs : EventArgs { public SomeEventArgs(int data) { this.SomeArg = data; } public int SomeArg { get; private set; } } Then my Main: public static void Main(string[] args) { var eventRaiser = new

In Rx, how to group events by id and throttle each group by multiple TimeSpans?

让人想犯罪 __ 提交于 2019-12-06 00:51:13
问题 I got into a Rx spree, so to speak, and this question is related to mine here and here. Nevertheless, maybe these are of help to someone as I could see them as useful variations of the same theme. Question: How could one group a random stream of int (say, on interval [0, 10] produced on random interval) objects into groups and provide for earch group a variable number of absence of events alarms (for the lack of better definition, for futher background see linked posts). More specifically

Convert event without EventArgs using Observable.FromEvent

。_饼干妹妹 提交于 2019-12-05 23:24:40
问题 I'm struggling with converting the following event to an IObservable : public delegate void _dispSolutionEvents_OpenedEventHandler(); event _dispSolutionEvents_OpenedEventHandler Opened; The event comes from a library so I can't change it. The overload of IObservable.FromEvent that should do it has the following signature: public static IObservable<Unit> FromEvent ( Action<Action> addHandler , Action<Action> removeHandler ) So I tried converting the event like this: var opened = Observable

Marble Diagrams [closed]

為{幸葍}努か 提交于 2019-12-05 22:55:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . The Marble diagrams are frequently from the Rx team explaining how certain operators in Rx work. Are there any tool to create the marble diagrams? 回答1: I've thought about creating a tool like this a fair bit having created quite a few of them in Visio (look on my blog for examples). I looked around to see if

waiting IObservable to get all elements error

谁都会走 提交于 2019-12-05 20:58:38
I have this class: public class TestService { public IObservable<int> GetObservable(int max) { var subject = new Subject<int>(); Task.Factory.StartNew(() => { for (int i = 0; i < max; i++) { subject.OnNext(i); } subject.OnCompleted(); }); return subject; } } I wrote a test method for this as well: [TestMethod] public void TestServiceTest1() { var testService = new TestService(); var i = 0; var observable = testService.GetObservable(3); observable.Subscribe(_ => { i++; }); observable.Wait(); Assert.AreEqual(i, 3); } But sometimes I get the error: Sequence contains no elements in method Wait().

How to serialize Observables to the cloud and back

烂漫一生 提交于 2019-12-05 20:03:41
I need to split processing sequence (like in this question How to organize sequence of data processors with .net RX ) into several computation units in Azure environment. The idea is to serialize Observable sequence to Azure Queues(or Service Bus) and to deserialize it back. If producer or consumer is failed other party should be able to continue producing/consuming. Could anyone suggest an elegant way to do so and what to use (Azure Queues or Service Bus)? Has anyone used TCP Observable provider - http://rxx.codeplex.com/wikipage?title=TCP%20Qbservable%20Provider for such problems is it safe

Catching events prior to subscription with FromEventPattern

ⅰ亾dé卋堺 提交于 2019-12-05 16:56:31
I'm writing a listener for messages using the Rx framework. The problem I'm facing is that the library I'm using uses a consumer that publishes events whenever a message has arrived. I've managed to consume the incoming messages via Observable.FromEventPattern but I have a problem with the messages that are already in the server. At the moment I have the following chain of commands Create a consumer Create an observable sequence with FromEventPattern and apply needed transformations Tell the consumer to start Subscribe to the sequence The easiest solution would be to swap steps 3. and 4. but

Is there an equivalent of the Task.ContinueWith operator in Rx?

冷暖自知 提交于 2019-12-05 16:06:49
Is there an equivalent of the Task.ContinueWith operator in Rx? I'm using Rx with Silverlight, I am making two webservice calls with the FromAsyncPattern method, and I'd like to do them synchronously . var o1 = Observable.FromAsyncPattern<int, string>(client.BeginGetData, client.EndGetData); var o2 = Observable.FromAsyncPattern<int, string>(client.BeginGetData, client.EndGetData); Is there an operator (like Zip) that will only start / subscribe to o2 only after o1 returns Completed? I handle failure of either web service call the same way. Yes, it's called projection: o1().SelectMany(_ => o2()

Confusion over behavior of Publish().Refcount()

爷,独闯天下 提交于 2019-12-05 15:57:19
I've got a simple program here that displays the number of letters in various words. It works as expected. static void Main(string[] args) { var word = new Subject<string>(); var wordPub = word.Publish().RefCount(); var length = word.Select(i => i.Length); var report = wordPub .GroupJoin(length, s => wordPub, s => Observable.Empty<int>(), (w, a) => new { Word = w, Lengths = a }) .SelectMany(i => i.Lengths.Select(j => new { Word = i.Word, Length = j })); report.Subscribe(i => Console.WriteLine($"{i.Word} {i.Length}")); word.OnNext("Apple"); word.OnNext("Banana"); word.OnNext("Cat"); word.OnNext

reactive extension OnNext

前提是你 提交于 2019-12-05 14:11:31
问题 With RX Subject, is it thread-safe to call OnNext() from multiple threads? So the sequence can be generated from multiple source. With merge do the same thing? 回答1: The Rx contract requires that notifications be sequential, and is a logical necessity for several operators. That said, you can use the available Synchronize methods to get this behaviour. var subject = new Subject<int>(); var syncedSubject = Subject.Synchronize(subject); You can now make concurrent calls to syncedSubject . For an