system.reactive

Why is RefCount not working after all initial subscribers disconnect?

给你一囗甜甜゛ 提交于 2019-12-05 05:39:01
Consider the following: [Fact] public void foo() { var result = new Subject<bool>(); var startCount = 0; var completionCount = 0; var obs = Observable .Defer(() => { ++startCount; return result.FirstAsync(); }) .Do(_ => ++completionCount) .Publish() .RefCount(); // pretend there are lots of subscribers at once var s1 = obs.Subscribe(); var s2 = obs.Subscribe(); var s3 = obs.Subscribe(); // even so, we only expect to be started once Assert.Equal(1, startCount); Assert.Equal(0, completionCount); // and we won't complete until the result ticks through result.OnNext(true); Assert.Equal(1,

How to read interleaved file concurrently using reactive extensions

南楼画角 提交于 2019-12-05 04:09:27
问题 I am new to the reactive extensions and I would like to use it (in c#) to read a file which contains several streams that are interleaved. Basically the file is in the format ABCDABCDABCD... . I would prefer to read the file sequentially and separate the streams (ie AAA.. , BBB.. , etc) and process each stream in parallel, using separate threads for each stream. There will have to be some form of buffering to make sure each stream can remain busy as much as possible (within limits of course).

How WinRT events are interoperate with .NET

有些话、适合烂在心里 提交于 2019-12-05 04:04:28
In the latest video by Rx team Bart De Smet: Rx Update - .NET 4.5, Async, WinRT I saw that WinRT events exposed to .NET by some really strange metadata, more preciesly - add_ / remove_ pair methods signature: EventRegistrationToken add_MyEvent(EventHandler<MyEventArgs> handler) { … } void remove_MyEvent(EventRegistrationToken registrationToken) { … } It looks really great, allowing unsubscribing from event by "disposing" the registration token (Rx does the same kind of thing, returning IDisposable instance from Subscribe() method). So it's became possible to easily unsubscribe lamba

Where to draw the line with reactive programming [closed]

若如初见. 提交于 2019-12-05 03:27:54
I have been using RxJava in my project for about a year now. With time, I grew to love it very much - now I'm thinking maybe too much... Most methods I write now have some form of Rx in it, which is great! (until it's not). I now notice that some methods require a lot of work to combine the different observable producing methods. I get the feeling that although I understand what I write now, the next programmer will have a really hard time understanding my code. Before I get to the bottom line let me give an example straight from my code in Kotlin (Don't dive too deep into it): private fun <T

How can I await that everything is done in a Rx observable sequence after unsubscribe?

一曲冷凌霜 提交于 2019-12-05 02:44:29
问题 Introduction In my WPF C# .NET application I use the reactive extensions (Rx) to subscribe to events and I often have to reload something from the DB to get the values I need to update the UI, because the event objects often only contains IDs and some meta data. I use the Rx scheduling to load the data in the background and update the UI on the dispatcher. I have made some bad experience with mixing "Task.Run" inside of a Rx sequence (when using "SelectMany" the order is no longer guaranteed

Rx - Divide stream into segments (lists) by condition

会有一股神秘感。 提交于 2019-12-05 02:27:24
I have an RX producer that creates a stream of strings like so (simplified version of the real stream): A1 A2 A3 B1 B2 C1 C2 C3 C4 C5 C6.... The stream is endless, but ordered. So after the strings that start with A run out, B starts. When B runs out, C starts... when Z run out, we move to AA1 etc. There's an unknown number of A 's, B 's etc, but it's typically 10-30 instances per letter. I'm looking for a way to divide this stream into blocks of all A's: A1 A2 A3 , all B's: B1 B2 , all C's: C1 C2 C3 C4 C5 C6 etc. Each block can be either an observable (which I'll turn into a list) or simply a

Using Rx to simplify an asynchronous Silverlight web service request

99封情书 提交于 2019-12-05 00:51:24
问题 I have written a simplified Silverlight client library for my WCF web service using Rx, however I notice sometimes I'm missing completed events. public IObservable<XElement> GetReport(string reportName) { return from client in Observable.Return(new WebServiceClient()) from request in Observable.ToAsync<string>(client.GetReportDataAsync)(reportName) from result in Observable.FromEvent<GetReportDataCompletedEventArgs>(client, "GetReportDataCompleted").Take(1) from close in this.CloseClient

Is there a Rx method to repeat the previous value periodically when no values are incoming?

ε祈祈猫儿з 提交于 2019-12-05 00:40:14
A use case which I have encountered, and I suspect I can't be the only one, is for a method like: IObservable<T> Observable.RepeatLastValueDuringSilence(this IObservable<T> inner, TimeSpan maxQuietPeriod); which would return all the future items from the inner observable, but also, if the inner observable doesn't call OnNext for a certain period of time (maxQuietPeriod), it just repeats the last value (until of course inner calls OnCompleted or OnError). A justification would be for a service to periodically ping out a periodic status update. For example: var myStatus = Observable.FromEvent( h

Non replaying hot observable

ぐ巨炮叔叔 提交于 2019-12-05 00:16:46
问题 Original question I have a scenario where I have multiple IObservable sequences which I want to combine with Merge and then listen to. However, if one of these produces an error I don't want it to crash everything for the other streams, as well as to resubscribe to the sequence (this is an 'ever lasting' sequence). I do this by appending a Retry() to the streams before merge, i.e.: IEnumerable<IObservable<int>> observables = GetObservables(); observables .Select(o => o.Retry()) .Merge()

Reactive Extensions - Properties update each other

只愿长相守 提交于 2019-12-05 00:05:17
问题 I have 2 DecimalUpDown controls, num_one and num_two, bound to properties First and Second respectively. When First is changed it will contact a server to calculate the value of Second, and vice-versa. Firing the server calls asynchronously freed the UI but, upon quick firing (scroll wheel for example), the last request isn't always the last to return so the values may become out of sync. Using Reactive I'm trying to Throttle the calls to only fire the server call after the user has stopped