Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/ReactiveUI.Tests/Commands/ReactiveCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using DynamicData;
Expand Down Expand Up @@ -1183,5 +1184,29 @@ public async Task ReactiveCommandCreateFromTaskHandlesTaskExceptionAsync()
Assert.False(isExecuting);
Assert.Equal("break execution", fail?.Message);
}

[Fact]
public async Task ReactiveCommandExecutesFromInvokeCommand()
{
var semaphore = new SemaphoreSlim(0);
var command = ReactiveCommand.Create(() => semaphore.Release());

Observable.Return(Unit.Default)
.InvokeCommand(command);

var result = 0;
var task = semaphore.WaitAsync();
if (await Task.WhenAny(Task.Delay(TimeSpan.FromMilliseconds(100)), task).ConfigureAwait(true) == task)
{
result = 1;
}
else
{
result = -1;
}

await Task.Delay(200).ConfigureAwait(false);
Assert.Equal(1, result);
}
}
}
7 changes: 4 additions & 3 deletions src/ReactiveUI/ReactiveCommand/ReactiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,14 @@ protected internal ReactiveCommand(
.CombineLatest(_isExecuting, (canEx, isEx) => canEx && !isEx)
.DistinctUntilChanged()
.Replay(1)
.RefCount()
.ObserveOn(_canExecuteScheduler);
.RefCount();

_results = _synchronizedExecutionInfo.Where(x => x.Demarcation == ExecutionDemarcation.Result)
.Select(x => x.Result);

_canExecuteSubscription = _canExecute.Subscribe(OnCanExecuteChanged);
_canExecuteSubscription = _canExecute
.ObserveOn(_canExecuteScheduler)
.Subscribe(OnCanExecuteChanged);
}

private enum ExecutionDemarcation
Expand Down