system.reactive

How to properly cancel a Task on ViewModel-deactivation with ReactiveUI?

 ̄綄美尐妖づ 提交于 2021-02-10 12:44:59
问题 In my MVVM application, when a ViewModel gets activated, a Task gets started that establishes a network connection and could take some time to complete. This Task is cancalable: private async Task ConnectAsync(CancellationToken cancellationToken = default) { ... } I'm using IActivatableViewModel to start it on ViewModel-activation like that: // Constructor: public SomeViewModel(...) { this.WhenActivated(disposable => { Observable.StartAsync(ConnectAsync); }); } Now what is the recommended

Generate events with dynamically changeable time interval

ぐ巨炮叔叔 提交于 2021-02-10 06:23:10
问题 I have a stream of numeric values that arrive at a fast rate (sub-millisecond), and I want to display their "instant value" on screen, and for usability reasons I should downsample that stream, updating the last value using a configurable time interval. That configuration would be done by user preference, via dragging a slider. So what I want to do is to store the last value of the source stream in a variable, and have an auto-retriggering timer that updates the displayed value with that

Does MailboxProcessor just duplicate IObservable?

限于喜欢 提交于 2021-02-09 10:50:49
问题 I want to process to types of a message Add x makes program remember number x Print makes it print all remembered numbers Why would I write this: open System type Message = | Add of int | Print let mailbox = new MailboxProcessor<Message>(fun inbox -> let rec loop history = async{ let! msg=inbox.Receive() match msg with | Add x -> return! loop(history + x.ToString()+" ") | Print -> printfn "%s" history return! loop(history) } loop "" ) [<EntryPoint>] let main argv = mailbox.Start() mailbox

How is an observable subscription gracefully terminated?

冷暖自知 提交于 2021-02-08 15:43:12
问题 I'm attempting to use Reactive Extensions (Rx) to process a stream of data. The processing of each element may take some time, though. To break the processing, I'm using a CancellationToken , which effectively stops the subscription. When cancel has been requested, how do I gracefully finish the current work and terminate properly without losing any data? Example var cts = new CancellationTokenSource(); cts.Token.Register(() => Console.WriteLine("Token cancelled.")); var observable =

Make an IObservable subscription concurrent

99封情书 提交于 2021-02-08 08:28:24
问题 I have the following code string dataDirectory = _settingsProvider.DataSettings.BaseDirectory; _solverManagementService.MergedPointCloudProducer(dataDirectory, cancellationToken) .Subscribe(PointCloudMergerCompleted); where the SolverManagementService _solverManagementService is Public class SolverManagementService : ISolverManagementService { public IObservable<IPointCloud> MergedPointCloudProducer(string dataDirectory, CancellationToken token) { return Observable.Create<IPointCloud>(

Rx.NET “gate” operator

家住魔仙堡 提交于 2021-02-08 03:01:13
问题 [Note: I am using 3.1 if that matters. Also, I've asked this on codereview but no responses so far.] I need an operator to allow a stream of booleans to act as a gate for another stream (let values pass when the gate stream is true, drop them when it's false). I would normally use Switch for this, but if the source stream is cold it will keep recreating it, which I don't want. I also want to clean up after myself, so that the result completes if either of the source or the gate complete.

Rx.NET “gate” operator

家住魔仙堡 提交于 2021-02-08 03:00:51
问题 [Note: I am using 3.1 if that matters. Also, I've asked this on codereview but no responses so far.] I need an operator to allow a stream of booleans to act as a gate for another stream (let values pass when the gate stream is true, drop them when it's false). I would normally use Switch for this, but if the source stream is cold it will keep recreating it, which I don't want. I also want to clean up after myself, so that the result completes if either of the source or the gate complete.

Limit replay buffer by observable

强颜欢笑 提交于 2021-02-07 18:14:17
问题 I have a stream with live data, and a stream which basically delimits parts of the live data that belong together. Now when someone subscribes to the live data stream, I would like to replay them the live data. However I don't want to remember all the live data, only the part since the last time the other stream emitted a value. There is an issue which would solve my problem, since there is a replay operator which does exactly what I want (or at least I think). What is currently the way to do

ObserveOnDispatcher not working

半城伤御伤魂 提交于 2021-02-07 03:53:51
问题 I have 2 threads, WPF+PIPE. I register the from the WPF on the pipe rx event. when using ObserveOnDispatcher() the registered handler is not called, when removing the ObserveOnDispatcher() it is called on the pipe thread. Does anyone have ideas why it is not called at all when using ObserveOnDispatcher()? 回答1: ObservableOnDispatcher takes the dispatcher of the current thread at the time when it is called. If you call it from a background thread, it will look for a dispatcher on that thread

ObserveOnDispatcher not working

牧云@^-^@ 提交于 2021-02-07 03:52:23
问题 I have 2 threads, WPF+PIPE. I register the from the WPF on the pipe rx event. when using ObserveOnDispatcher() the registered handler is not called, when removing the ObserveOnDispatcher() it is called on the pipe thread. Does anyone have ideas why it is not called at all when using ObserveOnDispatcher()? 回答1: ObservableOnDispatcher takes the dispatcher of the current thread at the time when it is called. If you call it from a background thread, it will look for a dispatcher on that thread