How to make ReactiveCommand Async?

I am using ReactiveCommand to get Async behavior. According to Paul Betz's comment in this discussion

If you are using RxUI 5.0, just use ReactiveCommand, now they are merged and have a better API.

I have the following code to check if this Async behavior is working. And this is not so. It freezes the user interface for 5 seconds.

MyReactiveCommand.Subscribe(s =>
{   
    Thread.Sleep(5000);
});

What am I missing?

+1
source share
3 answers

Try:

MyReactiveCommand
.RegisterAsyncAction(_ =>
                         {
                           Thread.Sleep(5000);
                         });

And if you need to return the result:

MyReactiveCommand
.RegisterAsyncFunction(o =>
                          {   
                            Thread.Sleep(5000);
                            return o.ToString();
                          })
.Subscribe(s => MessageBox.Show(string.Format("{0} was returned", s)));
+3
source

I fixed it using TaskPoolScheduler. Not sure if it should be so.

MyReactiveCommand
.ObserveOn(RxApp.TaskPoolScheduler)
.Subscribe(s =>
{   
    Thread.Sleep(5000);
});
0
source

ReactiveUI, , - . Async 1 , - , . , , 1 , - .

- Task.Delay , , .

, , , , , :

.SubscribeOn(RxApp.TaskPoolScheduler)

, - UI, , :

.ObserveOn(RxApp.MainThreadScheduler)

ObserveOn is where your IObserverable methods are OnNext / OnComplete / OnError context and SubscribeOn, where is the subscription implementation context.

0
source

All Articles