File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
ReactiveUI.Tests/Commands
ReactiveUI/ReactiveCommand Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 99using System . Reactive . Concurrency ;
1010using System . Reactive . Linq ;
1111using System . Reactive . Subjects ;
12+ using System . Threading ;
1213using System . Threading . Tasks ;
1314using System . Windows . Input ;
1415using DynamicData ;
@@ -1183,5 +1184,29 @@ public async Task ReactiveCommandCreateFromTaskHandlesTaskExceptionAsync()
11831184 Assert . False ( isExecuting ) ;
11841185 Assert . Equal ( "break execution" , fail ? . Message ) ;
11851186 }
1187+
1188+ [ Fact ]
1189+ public async Task ReactiveCommandExecutesFromInvokeCommand ( )
1190+ {
1191+ var semaphore = new SemaphoreSlim ( 0 ) ;
1192+ var command = ReactiveCommand . Create ( ( ) => semaphore . Release ( ) ) ;
1193+
1194+ Observable . Return ( Unit . Default )
1195+ . InvokeCommand ( command ) ;
1196+
1197+ var result = 0 ;
1198+ var task = semaphore . WaitAsync ( ) ;
1199+ if ( await Task . WhenAny ( Task . Delay ( TimeSpan . FromMilliseconds ( 100 ) ) , task ) . ConfigureAwait ( true ) == task )
1200+ {
1201+ result = 1 ;
1202+ }
1203+ else
1204+ {
1205+ result = - 1 ;
1206+ }
1207+
1208+ await Task . Delay ( 200 ) . ConfigureAwait ( false ) ;
1209+ Assert . Equal ( 1 , result ) ;
1210+ }
11861211 }
11871212}
Original file line number Diff line number Diff line change @@ -766,13 +766,14 @@ protected internal ReactiveCommand(
766766 . CombineLatest ( _isExecuting , ( canEx , isEx ) => canEx && ! isEx )
767767 . DistinctUntilChanged ( )
768768 . Replay ( 1 )
769- . RefCount ( )
770- . ObserveOn ( _canExecuteScheduler ) ;
769+ . RefCount ( ) ;
771770
772771 _results = _synchronizedExecutionInfo . Where ( x => x . Demarcation == ExecutionDemarcation . Result )
773772 . Select ( x => x . Result ) ;
774773
775- _canExecuteSubscription = _canExecute . Subscribe ( OnCanExecuteChanged ) ;
774+ _canExecuteSubscription = _canExecute
775+ . ObserveOn ( _canExecuteScheduler )
776+ . Subscribe ( OnCanExecuteChanged ) ;
776777 }
777778
778779 private enum ExecutionDemarcation
You can’t perform that action at this time.
0 commit comments