system.reactive

Fast Repeat TakeWhile causes infinite loop

北城余情 提交于 2019-12-12 08:41:21
问题 How can I make the following observable repeat until stream.DataAvailable is false? Currently it looks like it never stops. AsyncReadChunk and Observable.Return inside the Defer section make OnNext call then OnCompleted call. When Repeat receives the OnNext call it passes it to TakeWhile. When TakeWhile's is not satisfied it completes the observable but I think the OnCompleted that comes right after the OnNext is so fast that it makes Repeat to re-subscribes to the observable and causes the

Schedulers: Immediate vs. CurrentThread

别等时光非礼了梦想. 提交于 2019-12-12 08:28:33
问题 After reading the explanation for why Observable.Return(5) .Repeat() .Take(1) never completes, but Observable.Return(5, Scheduler.CurrentThread) .Repeat() .Take(1) works as expected. I am still confused and I can't tell why currentThread actually solves the problem. Can somebody give a clear explanation? 回答1: The link provided by Ned Stoyanov in the comments above has a great explanation by Dave Sexton. I'll try to illustrate it a bit differently. Take this example where a recursive call

Stream Multicasting - read a stream once but process it different ways, with minimal buffering

有些话、适合烂在心里 提交于 2019-12-12 07:38:33
问题 For scalability and to conserve resources, it is best to avoid reading an entire input stream into memory, but instead try to process it as a stream, reading small chunks at a time. This is easy to accomplish in .NET when you have one thing you want to do with the data, like read it from a web request and save it to a file. Easy example: input.CopyTo(output); // reads chunks of 4096 bytes and writes them to `output` But when I want to do multiple things with that data, it's quite a bit

Calculation on a realtime changing collection ( in c#)

风流意气都作罢 提交于 2019-12-12 04:14:41
问题 I have a changing collection of changing objects(add/delete in Collection as well as property changes are also possible). I want to get a new collection by some calculation on this Collection (summation / multiplication over some fields of all the objects having same value of a field). And bind calculated list to UI. for Ex: So I have a list of rate and qty of different qualities of several fruits and now I want to find a new list having avg rate and total quantity of each fruit(irrespective

How should one go about implementing a DistinctLatest (and caching) operator in Rx?

两盒软妹~` 提交于 2019-12-12 03:41:46
问题 I had a question A cache serving updates and new values as “DistinctLatest” and full cache contents upon subscription, which was well handled by the community. A question was raised that the actual goal of caching and replacing values like defined in the aforementioned question could be defined with a .DistinctLatest operator. OK! There doesn't seem to be much talk about such an operator. While searching, and thinking about it, I found ReactiveX: Group and Buffer only last item in each group,

Delay function to postpone IObservable values dynamically

邮差的信 提交于 2019-12-12 03:15:44
问题 [ This question is regarding IObservable / Rx ] Working Fixed Delay var frequency = TimeSpan.FromMinutes(5); Result.Delay(frequency).Subscribe(i => Debug.WriteLine("After Fixed Delay")); Pseudo-Code for Variable Delay Result.Delay(GetAsymptotingTime()).Subscribe(i => Debug.WriteLine("After Changing Delay")); While the code for variable delay compiles it gets called only once, providing only the first value (essentially a fixed value). How could you subscribe with a dynamic delay in Reactive

Reading from NetworkStream corrupts the buffer

南笙酒味 提交于 2019-12-12 02:06:03
问题 When reading data from NetworkStream with ReadUntilClosedObservable1, the returned data is corrupted like some blocks of read data overlap. However, when I read the data with ReadUntilClosedObservable2 the data arrives without problems. I want to use the ReadUntilClosedObservable1 because repeatedly reading from stream in ReadUntilClosedObservable2 is burning the CPU. How can I get the messages in sync order? UPDATE: return Observable.Timer(TimeSpan.Zero, interval, TaskPoolScheduler.Default)

Reactive Extensions: Why does this exit immediately?

烂漫一生 提交于 2019-12-11 21:26:24
问题 I am reading IntroToRx and I'm having a bit of trouble with the sample code. Here is the sum total of my code: using System; using System.Collections.Generic; using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Text; using System.Threading; using System.Threading.Tasks; namespace LearningReactiveExtensions { public class Program { static void Main(string[] args) { var observable = Observable.Interval(TimeSpan

Create observable and consume only between events

末鹿安然 提交于 2019-12-11 19:48:15
问题 Imagine the following scenario: I have this events: AfterLogin BeforeLogoff And AfterLogin, I have others events, based on new/others objects available.. When the user make a login, I need to create a new subscription and subscribe or handle it (using others events). When the user make a logoff, I need dispose these subscriptions and wait for AfterLogin again It is very similar to: Between values with Rx The big diference that it is necessary a "factory" to create a subscription and dispose

Is TakeWhile(…) and etc. extension methods thread safe in Rx 1.0?

混江龙づ霸主 提交于 2019-12-11 19:43:12
问题 I have an event source which fired by a Network I/O very frequently, based on underlying design, of course the event was always on different thread each time, now I wrapped this event via Rx with: Observable.FromEventPattern(...) , now I'm using the TakeWhile(predict) to filter some special event data. At now, I have some concerns on its thread safety, the TakeWhile(predict) works as a hit and mute , but in concurrent situation, can it still be guaranteed? because I guess the underlying