system.reactive

Creating Multiple Timers with Reactive Extensions

我只是一个虾纸丫 提交于 2019-12-19 11:02:24
问题 I've got a very simple class that I am using to poll a directory for new files. It's got the location, a time to start monitoring that location, and an interval (in hours) for when to check again: public class Thing { public string Name {get; set;} public Uri Uri { get; set;} public DateTimeOffset StartTime {get; set;} public double Interval {get; set;} } I am new to Reactive Extensions, but I think it is exactly the right tool for the job here. At the start time, and on every subsequent

Filtering a Touch.FrameReported IObservable using arbitrary boolean condition that changes over time

给你一囗甜甜゛ 提交于 2019-12-19 10:53:32
问题 I've been playing around with the Reactive Extensions (RX) in Windows Phone 7 and am very close to a working solution but got caught up on one small detail. I am trying to process the raw touch events using Touch.FrameReported and Observable.FromEvent (a bit of an educational quest to learn the Touch API and RX better), but I only want to process the events under certain conditions. For example I may want to filter the subscription to the touch down and touch up events only when a specific

Filtering a Touch.FrameReported IObservable using arbitrary boolean condition that changes over time

本秂侑毒 提交于 2019-12-19 10:53:10
问题 I've been playing around with the Reactive Extensions (RX) in Windows Phone 7 and am very close to a working solution but got caught up on one small detail. I am trying to process the raw touch events using Touch.FrameReported and Observable.FromEvent (a bit of an educational quest to learn the Touch API and RX better), but I only want to process the events under certain conditions. For example I may want to filter the subscription to the touch down and touch up events only when a specific

Observable from list of timetamps

旧时模样 提交于 2019-12-19 09:46:40
问题 If I have a list of objects that contains a timestamp - how can I make an observable that fire events at the relative time between the timestamps? Eg. if I have three objects with timestamps 2014-01-01 10:30, 2014-01-01 10:45 and 2014-01-01 11:30, I want the first event to fire right away, then the next 15 minutes later, and the last one 45 minutes after that. How can I speed up the process, so that 1 minute equals 1 second? So the first event would fire right away as before, but the next

Force flush to Observable.Buffer c#

爷,独闯天下 提交于 2019-12-19 03:43:08
问题 Is there any way to force a Observable.Buffer to flush before the end of buffered time? In the example: mSubscription = mFluxObservable.Buffer(new TimeSpan(0, 0, 1, 30)).Subscribe(o => saver(o, iSessionId)); I want to flush the data before the 1:30 period has finished! 回答1: This worked for me: var subject = new Subject<Unit>(); var closing = Observable .Timer(new TimeSpan(0, 0, 1, 30)) .Select(x => Unit.Default); var query = mFluxObservable .Buffer(() => Observable .Amb(subject, closing)

Reactive approach to simple imperative task

跟風遠走 提交于 2019-12-19 02:57:25
问题 Application requirements: subscribe to two event streams A and B for each A event there should be corresponding B event some time later the application monitors A events and alerts if no corresponding B arrives (in time) B events can arrive in a different order from the A events (but only after), late, or not at all This is simple in a traditional approach: record each A event in a collection remove the A event when a corresponding B event arrives monitor the collection for A events that don

RxJava: How to conditionally apply Operators to an Observable without breaking the chain

你。 提交于 2019-12-18 13:02:00
问题 I have a chain of operators on an RxJava observable. I'd like to be able to apply one of two operators depending on a boolean value without "breaking the chain". I'm relatively new to Rx(Java) and I feel like there's probably a more idiomatic and readable way of doing this than my current approach of introducing a temporary variable. Here's a concrete example, buffering items from an observable if a batch size field is non-null, otherwise emitting a single batch of unbounded size with toList(

When to use Observable.FromEventPattern rather than Observable.FromEvent?

痞子三分冷 提交于 2019-12-18 10:37:38
问题 We've got a client calling off to a TIBCO EMS queue and are wiring up the events like this: var msgConsumer = _session.CreateConsumer(responseQueue); var response = Observable.FromEvent<EMSMessageHandler,EMSMessageEventArgs> (h => msgConsumer.MessageHandler += h, h => msgConsumer.MessageHandler -= h) .Where(arg => arg.Message.CorrelationID == message.MessageID); When I call response.Subscribe(...) I get System.ArgumentException "Error binding to target method." I can make it work with

Should IObservable be preferred over events when exposing notifications in a library targeting .NET 4+

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 10:35:15
问题 I have a .NET library which, as part of an Object Model will emit notifications of certain occurrences. It would seem to me that the main pros of events are approachability for beginners (and simplicity in certain consumption contexts) with the main negative being that they are not composable and hence are immediately forced into an Observable.FromEvent * if you want to do anything interesting without writing a code thicket. The nature of the problem being solved is such that the event

Implementing IObservable<T> from scratch

梦想的初衷 提交于 2019-12-18 10:05:37
问题 The Reactive Extensions come with a lot of helper methods for turning existing events and asynchronous operations into observables but how would you implement an IObservable<T> from scratch? IEnumerable has the lovely yield keyword to make it very simple to implement. What is the proper way of implementing IObservable<T>? Do I need to worry about thread safety? I know there is support for getting called back on a specific synchronization context but is this something I as an IObservable<T>