system.reactive

Rx how to take first n elements of a sequence within time interval and ignore others

别说谁变了你拦得住时间么 提交于 2020-01-15 13:39:45
问题 I'm using Rx in my programm and want to create subscription for observable that takes 5 first elements within one minute time interval and ignores others. For example, Sequence: -1---2--3--4-5---6---7-8-------------- Interval: |------------------|------------------| Result: |1---2--3--4-5-----|-7-8--------------| Any thoughts? Thanks in advance 回答1: Window + SelectMany + Take would work in this case: var subscription = source.Window(TimeSpan.FromMinutes(1)) .SelectMany(w => w.Take(5))

C# reactive extensions what happens when OnNext take long time and observable producing new events

风流意气都作罢 提交于 2020-01-15 05:28:08
问题 I'm new to Rx and I'm thinking what happens when IObservable is producing lot of events very quickly and OnNext take very long time. I guess that new events are queued somehow internally so I can possible run our memory. Am I right? Consider following small example: Subject<int> subject = new Subject<int>(); subject.ObserveOn(Scheduler.ThreadPool).Subscribe(x => { Console.WriteLine("Value published: {0}", x); Thread.Sleep(100); }, () => Console.WriteLine("Sequence Completed.")); for (int i =

Take first elements of stream after previous element matches condition

核能气质少年 提交于 2020-01-15 03:31:05
问题 I'm new to reactive extensions (rx) and try to do the following thing in .NET (but should be the same in JS and other languages.): I have a stream incoming with objects containing a string and a bool property. The stream would be infinite. I have the following conditions: The first object should always be printed. Now all incoming objects should be skipped until an object arrives with the bool property set to "true". When an object arrives with the bool property set to "true", this object

Do 'Intermediate IObservables' without final subscribers get kept in memory for the lifetime of the root IObservable

与世无争的帅哥 提交于 2020-01-14 09:59:10
问题 For example, consider this: public IDisposable Subscribe<T>(IObserver<T> observer) { return eventStream.Where(e => e is T).Cast<T>().Subscribe(observer); } The eventStream is a long lived source of events. A short lived client will use this method to subscribe for some period of time, and then unsubscribe by calling Dispose on the returned IDisposable . However, while the eventStream still exists and should be kept in memory, there has been 2 new IObservables created by this method - the one

How to make delay in calling textchanged event of textbox in wpf

こ雲淡風輕ζ 提交于 2020-01-13 19:15:08
问题 I have custom control inherited from Textbox. I want to make delay in calling textchanged event. Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>( handler => this.TextChanged += handler, handler => this.TextChanged -= handler ).Throttle(TimeSpan.FromMilliseconds(600)) .Where(e => { var control= e.Sender as TextBox; return control!= null && !string.IsNullOrEmpty(control.Text); }) .Subscribe(x => Control_TextChanged(x.Sender, x.EventArgs)); Problem is it is giving

Is Reactive Extensions 2.1 PCL compatible with Xamarin?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 05:54:06
问题 Riddle me this: Can the new PCL version of Reactive Extensions be made to work with Xamarin? If so, how? 回答1: Nope. But check out https://github.com/mono/rx/tree/rx-oss-v2.1/Rx/NET/Source/Rx_Xamarin for versions that do work. 回答2: Yes it is possible. At the moment, you will need to switch to the beta channel of the Xamarin tools which implement Mono 3.0. This can be done via Tools > Options > Xamarin in Visual Studio 2012. Xamarin.Android 4.7 Information Xamarin.iOS 6.3 Information The

TakeUntil not working as documented?

爷,独闯天下 提交于 2020-01-13 05:06:09
问题 From the docs for the TakeUntil operator (emphasis mine): The TakeUntil subscribes and begins mirroring the source Observable. It also monitors a second Observable that you provide. If this second Observable emits an item or sends a termination notification , the Observable returned by TakeUntil stops mirroring the source Observable and terminates . If this is true, then why does this block?: Observable.Never<Unit>() .TakeUntil(Observable.Empty<Unit>()) .Wait(); 回答1: Preston Guillot is on

How to avoid the use of Subjects in RX

左心房为你撑大大i 提交于 2020-01-12 14:00:10
问题 So I keep reading everywhere that use of Subject<T> is "bad" - and I kind of agree with the reasoning. However, I am trying to think of the best way to avoid using it and have an example. Currently I have an abstract class for my persisted configuration classes that has a protected Save() method on it which is called whenever changing a property should persist the class. This message pumps a message onto a Subject<T> which is exposed through IObservable<T> interface which the serialisation

What's the best way to structure this Linq-to-Events Drag & Drop code?

南笙酒味 提交于 2020-01-12 08:39:33
问题 I am trying to handle a drag & drop interaction, which involves mouse down, mouse move, and mouse up. Here is a simplified repro of my solution that: on mouse down, creates an ellipse and adds it to a canvas on mouse move, repositions the ellipse to follow the mouse on mouse up, changes the colour of the canvas so that it's obvious which one you're dragging. var mouseDown = Observable.FromEvent<MouseButtonEventArgs>(canvas, "MouseLeftButtonDown"); var mouseUp = Observable.FromEvent

Select Many in Rx [closed]

可紊 提交于 2020-01-11 19:59:27
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Please any one let me know how the SelectMany operator in Rx works. I don't know more about this operator in Linq either. Please explain this with the help of a simple example, and also in what occasion we will use this operator in Rx. 回答1: SelectMany combines projection and