system.reactive

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

混江龙づ霸主 提交于 2019-12-09 23:18:20
问题 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

Reactive Framework / DoubleClick

江枫思渺然 提交于 2019-12-09 19:31:08
问题 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.... 回答1: The TimeInterval method

How to combine n observables dynamically into a list?

做~自己de王妃 提交于 2019-12-09 18:16:31
问题 I have a collection of observables that generate state changes for a so-called Channel . And I have a ChannelSet that should monitor those channels. I would like to write something like this: if one channel is operational, the channel set is up, else, the channel set is down. IEnumerable<ChannelState> channelStates = ...; if (channelStates.Any(cs => cs == ChannelState.Operational)) channelSet.ChannelSetState = ChannelSetState.Up; else channelSet.ChannelSetState = ChannelSetState.Down; But

How to complete a Rx Observable depending on a condition in a event

故事扮演 提交于 2019-12-09 17:39:08
问题 I have a event that I'm not in control of which provides me with data. The eventArgs looks something like this: class MyEventArg { bool IsLastItem {get;} Data DataItem {get;} } I use Rx to convert this event to an IObservable. But I want to complete the observable if IsLastItem is true. Any elegant ideas? One way would be to pipe the data through a subject that I have more control over to set the OnComplete event if the condition occurs... 回答1: If you want the last element to be included you

Reactive: Latest value to be received by IObservable

情到浓时终转凉″ 提交于 2019-12-09 17:07:05
问题 I know that the following is a blocking call and will return the first value in the observable sequence: var result = myObservable.First(); Depending on what type of subject I use this has different implications: Subject - First() will block until the OnNext() is next called which means eventually this will be the latest value BehaviorSubject - First() will block until at least one value has been pushed through OnNext() and because BehaviorSubject tracks the last value this will be the latest

Why does Observable.Generate() throw System.StackOverflowException?

我是研究僧i 提交于 2019-12-09 16:17:37
问题 I´m writing a C# (.NET 4.5) application that is used to aggregate time based events for reporting purposes. To make my query logic reusable for both realtime and historical data I make use of the Reactive Extensions (2.0) and their IScheduler infrastructure ( HistoricalScheduler and friends). For example, assume we create a list of events (sorted chronologically, but they may coincide!) whose only payload ist their timestamp and want to know their distribution across buffers of a fixed

Is there a more elegant way to merge observables when return type is unimportant?

早过忘川 提交于 2019-12-09 12:41:05
问题 I have a ReactiveUI-like view model. It has several properties of different types which fire NotifyPropertyChanged events and I want to subscribe a method that will be called when any is fired, but I am not interested in actual values. My current code is a bit ugly (due to opaque true selects). Is there a way to express this which shows the intention of just caring when the event occurs? this.ObservableForProperty(m => m.PropertyOne) .Select(_ => true) .Merge(this.ObservableForProperty(m => m

Get IObservable from all Property Changed events on T.MyProperty in SortedList<MyClass>

天涯浪子 提交于 2019-12-09 11:10:52
问题 I have a Class, MyClass that implements INotifyPropertyChanged and has some properties that implement PropertyChanged . When MyClass.MyProperty changes, PropertyChanged fires as expected. Another class contains a SortedList<MyClass> .I've tried merging the events into a single observable in the class that contains the SortedSet<MyClass> and subscribing to it, but it doesn't seem to ever have any events. Here's what I'm trying: Observable.Merge(MySortedList.ToObservable()) .Subscribe(evt =>

Rx observable which publishes a value if certain timeout expires

瘦欲@ 提交于 2019-12-09 00:57:23
问题 I have a method that returns an observable. This observable should (if evetything is working right) publish a value each second. What I would like to do is have it publish some custom alert value if a certain time has passed with no output. private IObservable<string> GetStatus() { return statusProvider .Subscribe(statusKey) //returns an IObservable<string> .Select(st => st.ToUpper()) .DistinctUntilChanged() .TakeUntil(disposed) .Replay(1) .RefCount(); } Is there a simple way for me to modify

Recursive / fan-out in Reactive Extensions

你。 提交于 2019-12-09 00:45:43
问题 I'm attempting to piece together a Rx pipeline that works as follows: I have written a function that takes in an IObservable providing me with profiles containing information about a company I query a variety of data sources to find potentially related company profiles, all in parallel. I merge that into a single IObservable of company profiles. When I get back these potentially related profiles, I compare them to profiles that I have already observed and, if they have a relevance > 80% and