system.reactive

Force flush count-type Observable.Buffer c#

痴心易碎 提交于 2019-12-11 08:32:46
问题 Building on this question which discusses flushing a time-based buffer: Force flush to Observable.Buffer c#, I'm having difficulty working out how to translate this answer given there to the case where I'm buffering by count, not by time: 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) .Take(1)); I started using the same Amb logic, using an

How to retrieve lifetime operations of a sequence generator using Rx?

拥有回忆 提交于 2019-12-11 07:53:01
问题 I need way to retrieve all the objects previously generated by a sequence, alongside the new ones, when I'm notified of changes on it, using Rx. I think this is uncommon, since most systems will just want the unprocessed entries, but my situation needs the whole set of values, old and new, to work. Is it possible to achieve this somehow? I couldn't find any similar examples and no method seem to do that. 回答1: You can use the Scan extension method for this. IObservable<T> source = ...;

How to implement my own operator in rx.net

对着背影说爱祢 提交于 2019-12-11 07:38:41
问题 I need the functionality of a hysteresis filter in RX. It should emit a value from the source stream only when the previously emitted value and the current input value differ by a certain amount. As a generic extension method, it could have the following signature: public static IObservable<T> HysteresisFilter<T>(this IObservable<t> source, Func<T/*previously emitted*/, T/*current*/, bool> filter) I was not able to figure out how to implement this with existing operators. I was looking for

Why/How should I use Publish without Connect?

China☆狼群 提交于 2019-12-11 07:19:30
问题 Why/how should I use .Publish() without a Connect or RefCount call following? What does it do? Example code: var source = new Subject<int>(); var pairs = source.Publish(_source => _source .Skip(1) .Zip(_source, (newer, older) => (older, newer)) ); pairs.Subscribe(p => Console.WriteLine(p)); source.OnNext(1); source.OnNext(2); source.OnNext(3); source.OnNext(4); How is pairs different from pairs2 here: var pairs2 = source .Skip(1) .Zip(source, (newer, older) => (older, newer)); 回答1: The

Alternative to using async () => in Rx Finally

て烟熏妆下的殇ゞ 提交于 2019-12-11 07:16:23
问题 My understanding is that async void , should be avoided and that async () => is just async void in disguise when used with Action . Hence, using the Rx.NET Finally operator asynchronously with async () => should be avoided since Finally accepts Action as parameter: IObservable<T>.Finally(async () => { await SomeCleanUpCodeAsync(); }; However, if this is bad practise, what is then best practice to use in the case where I need to asynchronously close a network coOnCompleted matter if my

Using Rx to execute delayed action once with cancellation for each window

北战南征 提交于 2019-12-11 06:57:45
问题 specifically I am trying to simulate performing an action if the key is held down for a duration greater than Threshold (T). I am trying to do this using Reactive Extensions .NET (The stable 1.0 version) without state variables. Here's the marble diagram of my inputs and what I need: let T = 3 (so 4 dddd without a key up event make up a "key held down") keyDown: --dddd---dd--d-dddddddddd---- keyUp: -----------u-----u--u---------------u-- desired: --------a---------------a---------- Here's

Retrieve XDocument only when modified using Rx + WebRequest + XDocument.Load

狂风中的少年 提交于 2019-12-11 05:34:15
问题 I have the following two observables System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://test.com/data.xml"); req.Method = "HEAD"; var ob = Observable.FromAsyncPattern(req.BeginGetResponse, req.EndGetResponse); ob().Select(x => x).Select(x => x.Headers["Last-Modified"]).DistinctUntilChanged(x => x); Observable .Interval(TimeSpan.FromSeconds(1.0)) .Select(_ => XDocument.Load("http://test.com/data.xml")); I would like it that the XDocument observable is only executed when "last

Is Reactive Extensions evaluating too many times?

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:12:59
问题 How many times is Reactive Extensions supposed to evaluate its various operators? I have the following test code: var seconds = Observable .Interval(TimeSpan.FromSeconds(5)) .Do(_ => Console.WriteLine("{0} Generated Data", DateTime.Now.ToLongTimeString())); var split = seconds .Do(_ => Console.WriteLine("{0} Split/Branch received Data", DateTime.Now.ToLongTimeString())); var merged = seconds .Merge(split) .Do(_ => Console.WriteLine("{0} Received Merged data", DateTime.Now.ToLongTimeString()))

Awaiting server responses in an async way to different calls at the same time

有些话、适合烂在心里 提交于 2019-12-11 04:57:56
问题 I am writing a client library for a model railway controller over TCP. The server is embedded in the control unit. When the client sends a command to the server, for example set(5, addr[3]) the server responds with a reply header <REPLY set(5, addr[3])> , results for that command and if there was an error. Because all this stuff is asynchronous, I have to match the replies with the commands. (Even if the client would only send one command and then wait for the response there are serverside

Subscribe to Observable.Retry() doesn't return until it completes?

放肆的年华 提交于 2019-12-11 04:36:24
问题 I expect IObservable.Subscribe to be asynchronous: whatever happens inside, I would like my subscription back. But Retry seems to have a different semantic: var retry = Observable.Throw(new Exception(), 0).Retry(); Console.WriteLine("got here"); var subscription = retry.Subscribe(); Console.WriteLine("didn't get here, ever"); There is clearly something I don't understand here. I guess using Retry with no parameters can't be used very often, or it should be used for something that I haven't