system.reactive

Observable.FromAsyncPattern with UDPClient.EndReceive and ref remote endpoint Parameter

旧街凉风 提交于 2019-12-22 18:09:36
问题 I'm learning about Reactive extensions and trying to re-factor some of my code. UDPClient.EndReceive takes a ref IPEndPoint parameter, so I currently have this working: UdpClient receiverUDP = new UdpClient(); receiverUDP.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); receiverUDP.EnableBroadcast = true; receiverUDP.Client.ExclusiveAddressUse = false; receiverUDP.Client.Bind(new IPEndPoint(IPAddress.Any, 1234)); IPEndPoint ep = null; var async =

Observable.FromAsyncPattern with UDPClient.EndReceive and ref remote endpoint Parameter

一曲冷凌霜 提交于 2019-12-22 18:08:10
问题 I'm learning about Reactive extensions and trying to re-factor some of my code. UDPClient.EndReceive takes a ref IPEndPoint parameter, so I currently have this working: UdpClient receiverUDP = new UdpClient(); receiverUDP.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); receiverUDP.EnableBroadcast = true; receiverUDP.Client.ExclusiveAddressUse = false; receiverUDP.Client.Bind(new IPEndPoint(IPAddress.Any, 1234)); IPEndPoint ep = null; var async =

Strange appearance of a null entry in the list of tasks

浪尽此生 提交于 2019-12-22 15:05:31
问题 Here is the code involved: private static async Task DoRunInOrderAsync<TTaskSeed>(SemaphoreSlim sem, IObservable<TTaskSeed> taskSeedSource, CreateTaskDelegate<TTaskSeed> createTask, OnTaskErrorDelegate<TTaskSeed> onFailed, OnTaskSuccessDelegate<TTaskSeed> onSuccess) where TTaskSeed : class { var tasks = await taskSeedSource .Select(taskSeed => GetPendingOrRunningTask(taskSeed, createTask, onFailed, onSuccess, sem)) .ToList() .ToTask(); await Task.WhenAll(tasks); } private static async Task

Strange appearance of a null entry in the list of tasks

狂风中的少年 提交于 2019-12-22 15:05:09
问题 Here is the code involved: private static async Task DoRunInOrderAsync<TTaskSeed>(SemaphoreSlim sem, IObservable<TTaskSeed> taskSeedSource, CreateTaskDelegate<TTaskSeed> createTask, OnTaskErrorDelegate<TTaskSeed> onFailed, OnTaskSuccessDelegate<TTaskSeed> onSuccess) where TTaskSeed : class { var tasks = await taskSeedSource .Select(taskSeed => GetPendingOrRunningTask(taskSeed, createTask, onFailed, onSuccess, sem)) .ToList() .ToTask(); await Task.WhenAll(tasks); } private static async Task

How to combine a slow moving observable with the most recent value of a fast moving observable

依然范特西╮ 提交于 2019-12-22 14:55:09
问题 A friend asked me this - I thought it was a good question so I am reposting it and my answer here: I have these two streams: var slowSource = Observable.Interval(TimeSpan.FromSeconds(1)); var fastSource = Observable.Interval(TimeSpan.FromMilliseconds(100)); and I’d like to combine them so that I produce output pairs which contain - The next value from slowSource - The most recent value from fastSource I only want one output pair per value from slowSource. For example, the first three output

waiting IObservable to get all elements error

只谈情不闲聊 提交于 2019-12-22 10:59:43
问题 I have this class: public class TestService { public IObservable<int> GetObservable(int max) { var subject = new Subject<int>(); Task.Factory.StartNew(() => { for (int i = 0; i < max; i++) { subject.OnNext(i); } subject.OnCompleted(); }); return subject; } } I wrote a test method for this as well: [TestMethod] public void TestServiceTest1() { var testService = new TestService(); var i = 0; var observable = testService.GetObservable(3); observable.Subscribe(_ => { i++; }); observable.Wait();

Converting a IEnumerable<T> to IObservable<T>, with maximum parallelism

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 08:12:51
问题 I have a sequence of async tasks to do (say, fetch N web pages). Now what I want is to expose them all as an IObservable<T> . My current solution uses the answer from this question: async Task<ResultObj> GetPage(string page) { Console.WriteLine("Before"); var result = await FetchFromInternet(page); Console.WriteLine("After"); return result; } // pages is an IEnumerable<string> IObservable<ResultObj> resultObservable =pages.Select(GetPage). Select(t => Observable.FromAsync(() => t)).Merge(); /

Generate infinite sequence of Natural numbers using RxJava

做~自己de王妃 提交于 2019-12-22 05:29:14
问题 I am trying to write a simple program using RxJava to generate an infinite sequence of natural numbers. So, far I have found two ways to generate sequence of numbers using Observable.timer() and Observable.interval() . I am not sure if these functions are the right way to approach this problem. I was expecting a simple function like one we have in Java 8 to generate infinite natural numbers. IntStream.iterate(1, value -> value +1).forEach(System.out::println); I tried using IntStream with

Why is RefCount not working after all initial subscribers disconnect?

那年仲夏 提交于 2019-12-22 05:15:28
问题 Consider the following: [Fact] public void foo() { var result = new Subject<bool>(); var startCount = 0; var completionCount = 0; var obs = Observable .Defer(() => { ++startCount; return result.FirstAsync(); }) .Do(_ => ++completionCount) .Publish() .RefCount(); // pretend there are lots of subscribers at once var s1 = obs.Subscribe(); var s2 = obs.Subscribe(); var s3 = obs.Subscribe(); // even so, we only expect to be started once Assert.Equal(1, startCount); Assert.Equal(0, completionCount)

How WinRT events are interoperate with .NET

折月煮酒 提交于 2019-12-22 04:25:10
问题 In the latest video by Rx team Bart De Smet: Rx Update - .NET 4.5, Async, WinRT I saw that WinRT events exposed to .NET by some really strange metadata, more preciesly - add_ / remove_ pair methods signature: EventRegistrationToken add_MyEvent(EventHandler<MyEventArgs> handler) { … } void remove_MyEvent(EventRegistrationToken registrationToken) { … } It looks really great, allowing unsubscribing from event by "disposing" the registration token (Rx does the same kind of thing, returning