rx.net

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

Throttle but discard results if they come too late

醉酒当歌 提交于 2019-12-11 01:22:29
问题 I'm writing a UI where the user can type in a search term and a list get continuously updated offering suggestions. My first though was that the Rx primitive Throttle was a perfect match but it gets me half there. The suggestions take a while to fetch so I get them asynchronously on not on the UI thread. The problem is that I want to discard/skip/throw away a result if the user types af the throttle time span again. For example: Time starts and the user presses a key : 0ms The throttle is set

RX.Net : Use Retry but log any Exception

大城市里の小女人 提交于 2019-12-10 16:58:35
问题 I am new to RX and have been investigating error handling and the use of Retry; I have the following (yes I know it's not a 'real' unit test but it gives me place to fiddle!!) and was wondering how I go about keeping the Retry but be able to log any Exception? [Test] public void Test() { var scheduler = new TestScheduler(); var source = scheduler.CreateHotObservable( new Recorded<Notification<long>>(10000000, Notification.CreateOnNext(0L)), new Recorded<Notification<long>>(20000000,

Reading from Stream using Observable through FromAsyncPattern, how to close/cancel properly

穿精又带淫゛_ 提交于 2019-12-07 18:26:15
问题 Need: long-running program with TCP connections A C# 4.0 (VS1010, XP) program needs to connect to a host using TCP, send and receive bytes, sometimes close the connection properly and reopen it later. Surrounding code is written using Rx.Net Observable style. The volume of data is low but the program should runs continuously (avoid memory leak by taking care of properly disposing resources). The text below is long because I explain what I searched and found. It now appears to work. Overall

How to use Rx.Nex extension ForEachAsync with async action

旧城冷巷雨未停 提交于 2019-12-07 04:50:00
问题 I have code which streams data down from SQL and writes it to a different store. The code is approximately this: using (var cmd = new SqlCommand("select * from MyTable", connection)) { using (var reader = await cmd.ExecuteReaderAsync()) { var list = new List<MyData>(); while (await reader.ReadAsync()) { var row = GetRow(reader); list.Add(row); if (list.Count == BatchSize) { await WriteDataAsync(list); list.Clear(); } } if (list.Count > 0) { await WriteDataAsync(list); } } } I would like to

With Reactive Extensions (RX), is it possible to add a “Pause” command?

落花浮王杯 提交于 2019-12-06 03:47:23
问题 I have a class which takes in a stream of events, and pushes out another stream of events. All of the events use Reactive Extensions (RX). The incoming stream of events is pushed from an external source into an IObserver<T> using .OnNext , and the outgoing stream of events is pushed out using IObservable<T> and .Subscribe . I am using Subject<T> to manage this, behind the scenes. I am wondering what techniques there are in RX to pause the output temporarily. This would mean that incoming

With Reactive Extensions (RX), is it possible to add a “Pause” command?

做~自己de王妃 提交于 2019-12-04 08:22:47
I have a class which takes in a stream of events, and pushes out another stream of events. All of the events use Reactive Extensions (RX). The incoming stream of events is pushed from an external source into an IObserver<T> using .OnNext , and the outgoing stream of events is pushed out using IObservable<T> and .Subscribe . I am using Subject<T> to manage this, behind the scenes. I am wondering what techniques there are in RX to pause the output temporarily. This would mean that incoming events would build up in an internal queue, and when they are unpaused, the events would flow out again.

Rx: a zip-like operator that continues after one of the streams ended?

不想你离开。 提交于 2019-11-28 13:55:24
I'm looking to combine streams (observables) that start and end asynchronously: -1----1----1----1---|-> -2----2--|-> [ optional_zip(sum) ] -1----3----3----1---|-> What I need it for: Adding audio streams together. They're streams of audio "chunks", but I'm going to represent them with integers here. So there's the first clip playing: -1----1----1----1---|-> and then a second one starts, a bit later: -2----2--|-> The result of combining them by sum should be: -1----3----3----1---|-> But the standard zip completes if any of the zipped streams end. I want this optional_zip to keep going even if