Open1
AsyncReactiveProperty が実行中かどうかを判定
using Reactive.Bindings;
using System.Reactive.Subjects;
var isNotRunning = new ReactivePropertySlim<bool>(true);
var canExecuteSource = new Subject<bool>();
var command = canExecuteSource.ToAsyncReactiveCommand(
isNotRunning)
.WithSubscribe(async () =>
{
Console.WriteLine("Executing....");
await Task.Delay(5000);
Console.WriteLine("Executed!");
});
Console.WriteLine($"CanExecute: {command.CanExecute()}"); // canExecuteSource が false なので false
canExecuteSource.OnNext(true);
Console.WriteLine($"CanExecute: {command.CanExecute()}"); // canExecuteSource が true で isNotRunning が true なので true
var commandTask = command.ExecuteAsync();
await Task.Delay(1000);
Console.WriteLine($"IsNotRunning: {isNotRunning.Value}"); // 実行中なので false
await commandTask;
Console.WriteLine($"IsNotRunning: {isNotRunning.Value}"); // 実行完了なので true