system.reactive

F# Reactive wait for Observable to complete

 ̄綄美尐妖づ 提交于 2020-03-01 05:41:26
问题 I found a variety of SO questions on this but couldn't figure out an F# solution. I need to block wait for an event to fire at me to check the data it returns. I am using Rx to receive event 3 times: let disposable = Observable.take 3 ackNack |> Observable.subscribe ( fun (sender, data) -> Console.WriteLine("{0}", data.AckNack) Assert.True(data.TotalAckCount > 0u) ) I would like to either turn results into a list, so they can be checked later on by the test framework (xUnit), or wait for all

Batch processing using IObservable

微笑、不失礼 提交于 2020-02-01 05:08:04
问题 My server side sends me batches of messages. The no of messages in a batch and frequency is arbitrary. At times I get messages at 1 minute intervals and at times not messages for an hour. At times 1 message and at times 10. My current implementation uses Observable.Buffer(TimeSpan.FromSeconds(5)) to group and send the messages to subscriber. Instead of having to check every 5 seconds, is there a way to configure the Observable to say send your buffered messages to subscriber if there's a x

How to know which observable the next value comes from?

倖福魔咒の 提交于 2020-01-24 21:55:47
问题 Let's say I have something like this: var observable = observable1 .Merge(observable2) .Merge(observable3); var subscription = observable.Subscribe(ValueHandler); ... public void ValueHandler(string nextValue) { Console.WriteLine($"Next value {nextValue} produced by /* sourceObservable */"); } Short of adding that reference along with the value inside of each observable implementation, is there a way to get the source observable out of observable1 , observable2 and observable3 that produced

IObservable<T>.ToTask<T> method returns Task awaiting activation

橙三吉。 提交于 2020-01-24 02:46:10
问题 Why does task await forever?: var task = Observable .FromEventPattern<MessageResponseEventArgs>(communicator, "PushMessageRecieved") .Where(i => i.EventArgs.GetRequestFromReceivedMessage().Name == requestName) .Select(i => i.EventArgs) .RunAsync(System.Threading.CancellationToken.None) .ToTask(); task.Wait(); I know "PushMessageRecieved" is fired; I can set a break point on the Select lambda and hit it. But task.Wait() never moves. Better Update: FirstAsync() is what I am looking for: public

ReactiveCommand and ConnectableObservable

 ̄綄美尐妖づ 提交于 2020-01-23 18:55:27
问题 I'd like to wire a ReactiveCommand up to a ConnectableObservable, since the observable should be connectable by multiple subscribers. The problem is that ReactiveCommand will only call the Subscribe method on the ConnectableObservable, rather than the Connect method as I would like. The code below demonstrates what I'm trying to achieve. Notice the StartOrConnectService method that is called by service code. public class Foo { public IConnectableObservable<string> Connection { get; } public

Rx: EnumerableEx.For() vs Enumerable.SelectMany()

老子叫甜甜 提交于 2020-01-22 12:10:47
问题 System.Interactive.dll includes a For() method with the following implementation: IEnumerable<TResult> For<TSource, TResult>( IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> resultSelector) { return source.Select<TSource, IEnumerable<TResult>>(resultSelector).Concat<TResult>(); } Am I missing something or is this equivalent to the existing Enumerable.SelectMany() , minus this ? IEnumerable<TResult> SelectMany<TSource, TResult>( this IEnumerable<TSource> source, Func<TSource,

Rx: EnumerableEx.For() vs Enumerable.SelectMany()

与世无争的帅哥 提交于 2020-01-22 12:09:32
问题 System.Interactive.dll includes a For() method with the following implementation: IEnumerable<TResult> For<TSource, TResult>( IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> resultSelector) { return source.Select<TSource, IEnumerable<TResult>>(resultSelector).Concat<TResult>(); } Am I missing something or is this equivalent to the existing Enumerable.SelectMany() , minus this ? IEnumerable<TResult> SelectMany<TSource, TResult>( this IEnumerable<TSource> source, Func<TSource,

Filestream to RX throwing InvalidOperationException

和自甴很熟 提交于 2020-01-16 19:05:29
问题 I have set up a filewatcher to create me an observable stream of ticks whenever a file changes. This is then used as the trigger to start another repeated observable sequence that then reads the updated file contents from an open stream. The problem I have is if the file updates happen in large batches in quick succession, the code throws an InvalidOperationException with the message The stream is currently in use by a previous operation on the stream. Stack trace at System.IO.StreamReader

Rx how to take first n elements of a sequence within time interval and ignore others

两盒软妹~` 提交于 2020-01-15 13:42:54
问题 I'm using Rx in my programm and want to create subscription for observable that takes 5 first elements within one minute time interval and ignores others. For example, Sequence: -1---2--3--4-5---6---7-8-------------- Interval: |------------------|------------------| Result: |1---2--3--4-5-----|-7-8--------------| Any thoughts? Thanks in advance 回答1: Window + SelectMany + Take would work in this case: var subscription = source.Window(TimeSpan.FromMinutes(1)) .SelectMany(w => w.Take(5))

Rx how to take first n elements of a sequence within time interval and ignore others

╄→尐↘猪︶ㄣ 提交于 2020-01-15 13:41:58
问题 I'm using Rx in my programm and want to create subscription for observable that takes 5 first elements within one minute time interval and ignores others. For example, Sequence: -1---2--3--4-5---6---7-8-------------- Interval: |------------------|------------------| Result: |1---2--3--4-5-----|-7-8--------------| Any thoughts? Thanks in advance 回答1: Window + SelectMany + Take would work in this case: var subscription = source.Window(TimeSpan.FromMinutes(1)) .SelectMany(w => w.Take(5))