mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added explicit schedulers to some Rx calls
This commit is contained in:
parent
8571003cfd
commit
f8c640467f
@ -88,7 +88,7 @@ namespace Wabbajack
|
||||
/// Inspiration:
|
||||
/// http://reactivex.io/documentation/operators/debounce.html
|
||||
/// https://stackoverflow.com/questions/20034476/how-can-i-use-reactive-extensions-to-throttle-events-using-a-max-window-size
|
||||
public static IObservable<T> Debounce<T>(this IObservable<T> source, TimeSpan interval, IScheduler scheduler = null)
|
||||
public static IObservable<T> Debounce<T>(this IObservable<T> source, TimeSpan interval, IScheduler scheduler)
|
||||
{
|
||||
scheduler = scheduler ?? Scheduler.Default;
|
||||
return Observable.Create<T>(o =>
|
||||
@ -209,15 +209,6 @@ namespace Wabbajack
|
||||
});
|
||||
}
|
||||
|
||||
public static IObservable<T> DelayInitial<T>(this IObservable<T> source, TimeSpan delay)
|
||||
{
|
||||
return source.FlowSwitch(
|
||||
Observable.Return(System.Reactive.Unit.Default)
|
||||
.Delay(delay)
|
||||
.Select(_ => true)
|
||||
.StartWith(false));
|
||||
}
|
||||
|
||||
public static IObservable<T> DelayInitial<T>(this IObservable<T> source, TimeSpan delay, IScheduler scheduler)
|
||||
{
|
||||
return source.FlowSwitch(
|
||||
|
@ -80,7 +80,7 @@ namespace Wabbajack
|
||||
this.WhenAny(x => x.TargetPath)
|
||||
// Dont want to debounce the initial value, because we know it's null
|
||||
.Skip(1)
|
||||
.Debounce(TimeSpan.FromMilliseconds(200), RxApp.TaskpoolScheduler)
|
||||
.Debounce(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
|
||||
.StartWith(default(string)),
|
||||
resultSelector: (existsOption, type, path) => (ExistsOption: existsOption, Type: type, Path: path))
|
||||
.StartWith((ExistsOption: ExistCheckOption, Type: PathType, Path: TargetPath))
|
||||
|
@ -123,7 +123,7 @@ namespace Wabbajack
|
||||
|
||||
_image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath)
|
||||
// Throttle so that it only loads image after any sets of swaps have completed
|
||||
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.TaskpoolScheduler)
|
||||
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
|
||||
.DistinctUntilChanged()
|
||||
.ObserveOnGuiThread()
|
||||
.Select(path =>
|
||||
@ -174,7 +174,7 @@ namespace Wabbajack
|
||||
return compiler.PercentCompleted.StartWith(0);
|
||||
})
|
||||
.Switch()
|
||||
.Debounce(TimeSpan.FromMilliseconds(25))
|
||||
.Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler)
|
||||
.ToGuiProperty(this, nameof(PercentCompleted));
|
||||
|
||||
BeginCommand = ReactiveCommand.CreateFromTask(
|
||||
|
@ -98,7 +98,7 @@ namespace Wabbajack
|
||||
(this).WhenAny(x => x.ModListLocation.TargetPath),
|
||||
resultSelector: (state, path) => (State: state, Path: path))
|
||||
// A short throttle is a quick hack to make the above changes "atomic"
|
||||
.Throttle(TimeSpan.FromMilliseconds(25))
|
||||
.Throttle(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler)
|
||||
.Select(u =>
|
||||
{
|
||||
if (u.State.Failed) return null;
|
||||
@ -142,7 +142,7 @@ namespace Wabbajack
|
||||
|
||||
// If Mo2 folder changes and download location is empty, set it for convenience
|
||||
this.WhenAny(x => x.Mo2Folder)
|
||||
.DelayInitial(TimeSpan.FromMilliseconds(100))
|
||||
.DelayInitial(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
|
||||
.Where(x => Directory.Exists(x))
|
||||
.FlowSwitch(
|
||||
(this).WhenAny(x => x.DownloadLocation.Exists)
|
||||
|
@ -172,7 +172,7 @@ namespace Wabbajack
|
||||
return x.path;
|
||||
})
|
||||
// Throttle slightly so changes happen more atomically
|
||||
.Throttle(TimeSpan.FromMilliseconds(50))
|
||||
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
|
||||
.Replay(1)
|
||||
.RefCount();
|
||||
|
||||
@ -192,7 +192,7 @@ namespace Wabbajack
|
||||
|
||||
// Force GC collect when modlist changes, just to make sure we clean up any loose large items immediately
|
||||
this.WhenAny(x => x.ModList)
|
||||
.Delay(TimeSpan.FromMilliseconds(50))
|
||||
.Delay(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
|
||||
.Subscribe(x =>
|
||||
{
|
||||
GC.Collect();
|
||||
@ -252,7 +252,7 @@ namespace Wabbajack
|
||||
return installer.PercentCompleted.StartWith(0f);
|
||||
})
|
||||
.Switch()
|
||||
.Debounce(TimeSpan.FromMilliseconds(25))
|
||||
.Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler)
|
||||
.ToGuiProperty(this, nameof(PercentCompleted));
|
||||
|
||||
Slideshow = new SlideShow(this);
|
||||
|
@ -52,7 +52,7 @@ namespace Wabbajack
|
||||
this.WhenAny(x => x.IsActive)
|
||||
.Where(x => !x)
|
||||
.Skip(1)
|
||||
.Delay(TimeSpan.FromMilliseconds(50))
|
||||
.Delay(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
GC.Collect();
|
||||
|
@ -66,7 +66,7 @@ namespace Wabbajack
|
||||
this.WhenAny(x => x.Installer.Installing),
|
||||
resultSelector: (enabled, installing) => enabled && installing))
|
||||
// Block spam
|
||||
.Debounce(TimeSpan.FromMilliseconds(250))
|
||||
.Debounce(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler)
|
||||
.Scan(
|
||||
seed: 0,
|
||||
accumulator: (i, _) => i + 1)
|
||||
|
Loading…
Reference in New Issue
Block a user