system.reactive

Rx grouped throttling

拥有回忆 提交于 2019-12-11 04:36:10
问题 I have an IObservable<T> where T looks like public class Notification { public int Id { get; set; } public int Version { get; set; } } Notifications are produced at variable time intervals and for different notifications, where the version number get incremented with each updated per notification id. What would be a proper approach to throttle the observable for a specific period of time and then to receive distinct notifications with the latest Version field? So far I came up with this for

How to Select Head and Tail at the same time in Reactive Extensions

强颜欢笑 提交于 2019-12-11 04:03:58
问题 I would like to create the following combinator public static IObservable<U> HeadTailSelect<T, U> (this IObservable<T> source, Func<T, IObservable<T>, U> fn) { } The selector method should be passed the current event and an observable to all future events, the tail. It must be guaranteed that upon subscribing to the tail any time in the future the first received event will be the very next one that was received after the head. I'm aware that this will require some buffering but I'm not quite

What is the Rx.NET way to produce a cancellable observable of file names?

拟墨画扇 提交于 2019-12-11 03:53:38
问题 I would like to generate an observable of files, such that the discovery of the files names could be cancelled in any moment. For the sake of this example, the cancellation takes place in 1 second automatically. Here is my current code: class Program { static void Main() { try { RunAsync(@"\\abc\xyz").GetAwaiter().GetResult(); } catch (Exception exc) { Console.Error.WriteLine(exc); } Console.Write("Press Enter to exit"); Console.ReadLine(); } private static async Task RunAsync(string path) {

A class implementing two different IObservables?

旧城冷巷雨未停 提交于 2019-12-11 03:47:33
问题 I have a class with two events, call them StatusChanged and ValueChanged . I'm wondering about exposing these 'streams' as IObservable . Is implementing IObservable<Status> and IObservable<Value> on the same class 'bad'? Is it likely to cause me (or users of my class) grief? 回答1: Implementing a covariant interface for different types is a really bad idea. Consider what happens if you cast the class to IObservable<object> , which is now ambiguous. I'd rather have two properties IObservable

Ensuring sequential disposing of multiple IDisposables

五迷三道 提交于 2019-12-11 03:47:30
问题 I have two IDisposables that I need to have disposed in sequential order. The ordering is important since the first IDisposable kills an Rx subscription that is relying on a service that will be killed by the second IDisposable . This is within a Windows Forms application where the subscription of the IObservable needs to happen on a different thread but the observing and disposing needs to happen on the UI thread. (Actually, I don't care if the disposing happens on the UI thread as long as

Controlling what thread an Rx subscription is Disposed on after SubscribedOn has been used

*爱你&永不变心* 提交于 2019-12-11 03:37:49
问题 I have a Rx subscription that I SubscribeOn with a different thread to prevent it from blocking. However, I want the disposal of that subscription to block due to resource management issues. I have not been able to figure out how to accomplish this within the context of either a console app or a winforms app (I have both use cases). Below is working code of a reduced case that simulates what I am doing: internal class Program { private static void Log(string msg) { Console.WriteLine("[{0}] "

Throttle but discard results if they come too late

醉酒当歌 提交于 2019-12-11 01:22:29
问题 I'm writing a UI where the user can type in a search term and a list get continuously updated offering suggestions. My first though was that the Rx primitive Throttle was a perfect match but it gets me half there. The suggestions take a while to fetch so I get them asynchronously on not on the UI thread. The problem is that I want to discard/skip/throw away a result if the user types af the throttle time span again. For example: Time starts and the user presses a key : 0ms The throttle is set

simple rx code silently fails in windows forms only during debugging in visual studio 2010

蹲街弑〆低调 提交于 2019-12-11 01:17:17
问题 Feels like bugs and problems are attracted to me lately! =P So I finally took some time off today to explore a little Rx. Heres what I did: Here's the only piece of running code: private void button1_Click(object sender, EventArgs e) { var txtc = Observable.FromEvent<EventArgs>(textBox1, "TextChanged") .Throttle(TimeSpan.FromSeconds(0.5)) .SubscribeOnDispatcher();//**also tried .SubscribeOn(this) var t = from x in txtc select textBox1.Text; t.Subscribe(x => listBox1.Items.Add(x)); } Now, when

Notification when ReactiveCommand completes

一曲冷凌霜 提交于 2019-12-11 00:26:40
问题 I'm trying to use ReactiveUI ReactiveCommands to switch on and off a gRPC stream that I've converted into an observable. The code shown below works to some extent - the connect button will cause the stream to connect, and I start receiving data in the onNext handler of the subscribe. The disconnect button does also disconnect the stream via the cancellation token. However, once the disconnect command is executed, I would also like to be notified so I can clear up some other state in the

Unit testing something with ObserveOnDispatcher

拈花ヽ惹草 提交于 2019-12-11 00:13:25
问题 I've some code in my view model as follows: miService.GetSomething(par1, par2) .ObserveOnDispatcher() .Subscribe(dt => { DoSomething(dt); }); Then in my test, I'm "mocking" my service as follows: miService.Setup(ms => ms.GetSomething(....)) .Returns(Observable.Return(XYZ)); The problem is that due to the ObserveOnDispatcher, the subscribe delegate is never executed. I've seen some code with DispatcherFrame and PushFrame, but the problem is that I don't know "where", I can call frame.Continue