system.reactive

How to merge multiple observables with order preservation and maximum concurrency?

旧街凉风 提交于 2021-02-05 06:39:25
问题 I searched for a duplicate and didn't find any. What I have is a nested observable IObservable<IObservable<T>> , and I want to flatten it to a IObservable<T> . I don't want to use the Concat operator because it delays the subscription to each inner observable until the completion of the previous observable. This is a problem because the inner observables are cold, and I want them to start emitting T values immediately after they are emitted by the outer observable. I also don't want to use

Observing incoming websocket messages with Reactive Extensions?

自作多情 提交于 2021-02-04 16:09:14
问题 I want to use linq to process events received via a websocket connection. This is what I have so far: private static void Main() { string WsEndpoint = "wss://push.planetside2.com/streaming?environment=ps2&service-id=s:quicktesting"; using (WebSocket ws = new WebSocket(WsEndpoint)) { ws.OnMessage += Ws_OnMessage; ws.Connect(); Console.ReadKey(); ws.Close(); } } private static void Ws_OnMessage(object sender, MessageEventArgs e) { Console.WriteLine(e.Data); } The first think that stumps me is

Observing incoming websocket messages with Reactive Extensions?

那年仲夏 提交于 2021-02-04 16:08:36
问题 I want to use linq to process events received via a websocket connection. This is what I have so far: private static void Main() { string WsEndpoint = "wss://push.planetside2.com/streaming?environment=ps2&service-id=s:quicktesting"; using (WebSocket ws = new WebSocket(WsEndpoint)) { ws.OnMessage += Ws_OnMessage; ws.Connect(); Console.ReadKey(); ws.Close(); } } private static void Ws_OnMessage(object sender, MessageEventArgs e) { Console.WriteLine(e.Data); } The first think that stumps me is

How to bind a non-disposable object with each subscription of a cold observable?

纵然是瞬间 提交于 2021-02-04 08:37:04
问题 Sorry if this question has been asked before, but I can't find a duplicate. Also sorry for asking too many questions lately! I am probably searching for a custom Observable.Using method, that is not restricted to disposable resources. What I have is a cold IObservable that maintains some internal state, for example a Random instance. This instance should be bound not with the IObservable itself, but with each of its subscriptions. Each subscriber should use a different instance of this

How to convert an IGroupedObservable to IGrouping?

故事扮演 提交于 2021-01-29 08:14:59
问题 I have an observable sequence of elements that have a char Key property, that has values in the range from 'A' to 'E' . I want to group these elements based on this key. After grouping them I want the result to by an observable of groups, so that I can process each group separately. My problem is that I can't find a nice way to preserve the key of each group in the final observable. Here is an example of what I am trying to do: var observable = Observable .Interval(TimeSpan.FromMilliseconds

Testing rx with 'real' delay

本小妞迷上赌 提交于 2021-01-28 18:23:31
问题 I have been investigating the possibility of 'protecting' an observable source from a slow observer, by throwing away any new items that come in while the observer is working. After looking at ObserveLatestOn (and finding it a bit hard to understand...), I chanced on this answer, which suggested doing it in Subscribe, rather than inside the Observable monad. Which gives something like this (versions with delegate overloads not shown): public static IDisposable NonBlockingSubscribe<T>(this

RX - Multi consumers by key subscription complexity

 ̄綄美尐妖づ 提交于 2021-01-28 09:48:12
问题 I got an observable of KeyValuePair<int,double> : --(7|45.2)--(3|11.1)--(5|13.2)--(6|36.2)--(3|57.4) I got a list of consumers defined at runtime. They are only interested in values produced for a single key ( myKey ). For example: the consumer 7, is only interested in the value 45.2. the consumer 3, is only interested in the values 11.1 and 57.4 the consumer 1, is only interested in values with myKey = 1, so none here. Here is my consumer subscription code (one per consumer): myObservable

Is it possible to restart an IConnectableObservable?

时光怂恿深爱的人放手 提交于 2021-01-27 21:14:21
问题 I'm trying to figure out how to "restart" an IConnectableObservable after it has completed or errored. The code below shows two subscribers (A, B) to a connnectable observable. Once their subscription is disposed, a new subscriber (C) connects. I'd like it to appear to C that it is an entirely new observable, but I am only getting the exception raised in the first subscription. static void Main(string[] args) { var o = Observable.Create<string>(observer => { observer.OnNext("msg"); observer

Subscribe and immediately unsubscribe after first action

吃可爱长大的小学妹 提交于 2021-01-27 03:57:46
问题 I want to subscribe on an IObservable<T> and unsubscribe (dipose) the subscription right after receiving the first element of type T , i.e. I only want to call the action on the very first element I get after subscribing. This is the approach I came up with: public static class Extensions { public static void SubscribeOnce<T>(this IObservable<T> observable, Action<T> action) { IDisposable subscription = null; subscription = observable.Subscribe(t => { action(t); subscription.Dispose(); }); }

Running histogram stream with Rx

有些话、适合烂在心里 提交于 2021-01-27 02:36:28
问题 I have the following single letter stream A B C A D B A C D And from this stream, I would like a stream of running count per letter (A,1) (A,1), (B,1) (A,1), (B,1), (C,1) (A,2), (B,1), (C,1) (A,2), (B,1), (C,1), (D,1) (A,2), (B,2), (C,1), (D,1) (A,3), (B,2), (C,1), (D,1) (A,3), (B,2), (C,2), (D,1) (A,3), (B,2), (C,2), (D,2) , i.e at each new letter, the totals are updated and emitted. I guess this problem is fairly language agnostic, so don't hesitate to propose a solution in your language of