The idea behind ReactiveAsyncCommand
is that it intentionally constrains the number of in-flight requests. In this case, you want to forget about that constraint, so let's use regular ReactiveCommand
instead:
SearchCommand
.Select(x => Observable.Start(() => PerformSearch(x), RxApp.TaskPoolScheduler))
.Switch()
.ToProperty(this, x => x.SearchResults);
Note that Select.Switch
here is similar to SelectMany
, except that it will always maintain the order of inputs while throwing away old inputs if they don't complete in time.
Blah blah CancellationTokenSource blah blah TPL
In this case, the underlying method itself (_locationService.DeepLoad
) is synchronous - it's not possible to cancel the method in a safe way, so we have to just let cancelled results run to completion and ignore the result, which is what we'll end up doing here.
Edit: Here's an ugly hack to figure out whether items are in-flight or not:
SearchCommand
.Do(x => Interlocked.Increment(ref searchesInFlight))
.Select(x => Observable.Start(() => PerformSearch(x), RxApp.TaskPoolScheduler).Do(x => Interlocked.Decrement(ref searchesInFlight)))
.Switch()
.ToProperty(this, x => x.SearchResults);