From c1ac2d7a550c9130258dce22b7569ebdc73d8068 Mon Sep 17 00:00:00 2001 From: "Darrin W. Cullop" Date: Mon, 19 Feb 2024 23:16:29 -0800 Subject: [PATCH 1/3] Use centralized constant for Default IScheduler value --- src/DynamicData/Cache/Internal/AutoRefresh.cs | 3 ++- src/DynamicData/Cache/Internal/BatchIf.cs | 3 ++- .../Cache/Internal/GroupOnProperty.cs | 4 ++-- .../GroupOnPropertyWithImmutableState.cs | 4 ++-- .../Cache/Internal/ToObservableChangeSet.cs | 5 +++-- src/DynamicData/Cache/ObservableCacheEx.cs | 19 ++++++++++--------- .../Experimental/ExperimentalEx.cs | 3 ++- src/DynamicData/Internal/Defaults.cs | 12 ++++++++++++ src/DynamicData/List/Internal/AutoRefresh.cs | 4 ++-- src/DynamicData/List/Internal/BufferIf.cs | 3 ++- .../List/Internal/FilterOnObservable.cs | 3 ++- .../List/Internal/GroupOnProperty.cs | 4 ++-- .../GroupOnPropertyWithImmutableState.cs | 4 ++-- .../List/Internal/ToObservableChangeSet.cs | 5 +++-- src/DynamicData/List/ObservableListEx.cs | 11 ++++++----- 15 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 src/DynamicData/Internal/Defaults.cs diff --git a/src/DynamicData/Cache/Internal/AutoRefresh.cs b/src/DynamicData/Cache/Internal/AutoRefresh.cs index ecc6e0b72..04ea8eb82 100644 --- a/src/DynamicData/Cache/Internal/AutoRefresh.cs +++ b/src/DynamicData/Cache/Internal/AutoRefresh.cs @@ -5,6 +5,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; +using DynamicData.Internal; namespace DynamicData.Cache.Internal; @@ -14,7 +15,7 @@ internal sealed class AutoRefresh(IObservable> _reEvaluator = reEvaluator ?? throw new ArgumentNullException(nameof(reEvaluator)); - private readonly IScheduler _scheduler = scheduler ?? Scheduler.Default; + private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/Cache/Internal/BatchIf.cs b/src/DynamicData/Cache/Internal/BatchIf.cs index d96678fef..9907d3963 100644 --- a/src/DynamicData/Cache/Internal/BatchIf.cs +++ b/src/DynamicData/Cache/Internal/BatchIf.cs @@ -6,6 +6,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; +using DynamicData.Internal; namespace DynamicData.Cache.Internal; @@ -15,7 +16,7 @@ internal sealed class BatchIf(IObservable _pauseIfTrueSelector = pauseIfTrueSelector ?? throw new ArgumentNullException(nameof(pauseIfTrueSelector)); - private readonly IScheduler _scheduler = scheduler ?? Scheduler.Default; + private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/Cache/Internal/GroupOnProperty.cs b/src/DynamicData/Cache/Internal/GroupOnProperty.cs index a7353c36c..f189a935e 100644 --- a/src/DynamicData/Cache/Internal/GroupOnProperty.cs +++ b/src/DynamicData/Cache/Internal/GroupOnProperty.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; - +using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.Cache.Internal; @@ -28,7 +28,7 @@ public IObservable> Run() => _source.Publ // add a throttle if specified if (throttle is not null) { - regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Scheduler.Default); + regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Defaults.Scheduler); } // Use property changes as a trigger to re-evaluate Grouping diff --git a/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs b/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs index 7914ebd65..6c9cc9f3d 100644 --- a/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs +++ b/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; - +using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.Cache.Internal; @@ -17,7 +17,7 @@ internal sealed class GroupOnPropertyWithImmutableState(I where TGroup : notnull { private readonly Func _groupSelector = groupSelectorKey.Compile(); - private readonly IScheduler _scheduler = scheduler ?? Scheduler.Default; + private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs b/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs index 7b1656074..893b6701b 100644 --- a/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs +++ b/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs @@ -6,6 +6,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; +using DynamicData.Internal; namespace DynamicData.Cache.Internal; @@ -29,7 +30,7 @@ public ToObservableChangeSet( _expireAfter = expireAfter; _keySelector = keySelector; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Scheduler.Default; + _scheduler = scheduler ?? Defaults.Scheduler; _source = Observable.Create>(observer => { @@ -57,7 +58,7 @@ public ToObservableChangeSet( _expireAfter = expireAfter; _keySelector = keySelector; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Scheduler.Default; + _scheduler = scheduler ?? Defaults.Scheduler; _source = source; } diff --git a/src/DynamicData/Cache/ObservableCacheEx.cs b/src/DynamicData/Cache/ObservableCacheEx.cs index 78d07222e..92433c732 100644 --- a/src/DynamicData/Cache/ObservableCacheEx.cs +++ b/src/DynamicData/Cache/ObservableCacheEx.cs @@ -15,6 +15,7 @@ using DynamicData.Binding; using DynamicData.Cache; using DynamicData.Cache.Internal; +using DynamicData.Internal; using DynamicData.Kernel; // ReSharper disable once CheckNamespace @@ -324,7 +325,7 @@ public static IObservable> AutoRefresh( return t.WhenAnyPropertyChanged(); } - return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? Scheduler.Default); + return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? Defaults.Scheduler); }, changeSetBuffer, scheduler); @@ -356,7 +357,7 @@ public static IObservable> AutoRefresh> Batch(this I { source.ThrowArgumentNullExceptionIfNull(nameof(source)); - return source.Buffer(timeSpan, scheduler ?? Scheduler.Default).FlattenBufferResult(); + return source.Buffer(timeSpan, scheduler ?? Defaults.Scheduler).FlattenBufferResult(); } /// @@ -832,7 +833,7 @@ public static IObservable> BufferInitial source.DeferUntilLoaded().Publish( shared => { - var initial = shared.Buffer(initialBuffer, scheduler ?? Scheduler.Default).FlattenBufferResult().Take(1); + var initial = shared.Buffer(initialBuffer, scheduler ?? Defaults.Scheduler).FlattenBufferResult().Take(1); return initial.Concat(shared); }); @@ -1357,7 +1358,7 @@ public static IObservable> Except(this /// public static IObservable> ExpireAfter(this IObservable> source, Func timeSelector) where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, Scheduler.Default); + where TKey : notnull => ExpireAfter(source, timeSelector, Defaults.Scheduler); /// /// Automatically removes items from the stream after the time specified by @@ -1401,7 +1402,7 @@ public static IObservable> ExpireAfter( /// timeSelector. public static IObservable> ExpireAfter(this IObservable> source, Func timeSelector, TimeSpan? pollingInterval) where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, pollingInterval, Scheduler.Default); + where TKey : notnull => ExpireAfter(source, timeSelector, pollingInterval, Defaults.Scheduler); /// /// Automatically removes items from the stream on the next poll after the time specified by @@ -1463,7 +1464,7 @@ public static IObservable>> ExpireAfter< /// timeSelector. public static IObservable>> ExpireAfter(this ISourceCache source, Func timeSelector, TimeSpan? interval = null) where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, interval, Scheduler.Default); + where TKey : notnull => ExpireAfter(source, timeSelector, interval, Defaults.Scheduler); /// /// Ensures there are no duplicated keys in the observable changeset. @@ -1504,7 +1505,7 @@ public static IObservable>> ExpireAfter< source.ThrowArgumentNullExceptionIfNull(nameof(source)); timeSelector.ThrowArgumentNullExceptionIfNull(nameof(timeSelector)); - scheduler ??= Scheduler.Default; + scheduler ??= Defaults.Scheduler; return Observable.Create>>( observer => source.Connect().ForExpiry(timeSelector, pollingInterval, scheduler).Finally(observer.OnCompleted).Subscribe( @@ -2499,7 +2500,7 @@ public static IObservable>> LimitSizeTo< long orderItemWasAdded = -1; var sizeLimiter = new SizeLimiter(sizeLimit); - return source.Connect().Finally(observer.OnCompleted).ObserveOn(scheduler ?? Scheduler.Default).Transform((t, v) => new ExpirableItem(t, v, DateTime.Now, Interlocked.Increment(ref orderItemWasAdded))).Select(sizeLimiter.CloneAndReturnExpiredOnly).Where(expired => expired.Length != 0).Subscribe( + return source.Connect().Finally(observer.OnCompleted).ObserveOn(scheduler ?? Defaults.Scheduler).Transform((t, v) => new ExpirableItem(t, v, DateTime.Now, Interlocked.Increment(ref orderItemWasAdded))).Select(sizeLimiter.CloneAndReturnExpiredOnly).Where(expired => expired.Length != 0).Subscribe( toRemove => { try diff --git a/src/DynamicData/Experimental/ExperimentalEx.cs b/src/DynamicData/Experimental/ExperimentalEx.cs index c574f9b0f..5fa1906a4 100644 --- a/src/DynamicData/Experimental/ExperimentalEx.cs +++ b/src/DynamicData/Experimental/ExperimentalEx.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for full license information. using System.Reactive.Concurrency; +using DynamicData.Internal; namespace DynamicData.Experimental; @@ -26,6 +27,6 @@ public static IWatcher AsWatcher(this IObservable< { source.ThrowArgumentNullExceptionIfNull(nameof(source)); - return new Watcher(source, scheduler ?? Scheduler.Default); + return new Watcher(source, scheduler ?? Defaults.Scheduler); } } diff --git a/src/DynamicData/Internal/Defaults.cs b/src/DynamicData/Internal/Defaults.cs new file mode 100644 index 000000000..23fd87412 --- /dev/null +++ b/src/DynamicData/Internal/Defaults.cs @@ -0,0 +1,12 @@ +// Copyright (c) 2011-2023 Roland Pheasant. All rights reserved. +// Roland Pheasant licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +using System.Reactive.Concurrency; + +namespace DynamicData.Internal; + +internal static class Defaults +{ + public static IScheduler Scheduler { get; } = TaskPoolScheduler.Default; +} diff --git a/src/DynamicData/List/Internal/AutoRefresh.cs b/src/DynamicData/List/Internal/AutoRefresh.cs index 7b6d0f7fc..655733576 100644 --- a/src/DynamicData/List/Internal/AutoRefresh.cs +++ b/src/DynamicData/List/Internal/AutoRefresh.cs @@ -5,7 +5,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; - +using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.List.Internal; @@ -32,7 +32,7 @@ public IObservable> Run() => Observable.Create> itemsChanged = buffer is null ? itemHasChanged.Select(t => new[] { t }) : - itemHasChanged.Buffer(buffer.Value, scheduler ?? Scheduler.Default).Where(list => list.Count > 0); + itemHasChanged.Buffer(buffer.Value, scheduler ?? Defaults.Scheduler).Where(list => list.Count > 0); IObservable> requiresRefresh = itemsChanged.Synchronize(locker).Select( items => // catch all the indices of items which have been refreshed diff --git a/src/DynamicData/List/Internal/BufferIf.cs b/src/DynamicData/List/Internal/BufferIf.cs index 06c22fbe2..ff394993e 100644 --- a/src/DynamicData/List/Internal/BufferIf.cs +++ b/src/DynamicData/List/Internal/BufferIf.cs @@ -6,6 +6,7 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using System.Reactive.Subjects; +using DynamicData.Internal; namespace DynamicData.List.Internal; @@ -14,7 +15,7 @@ internal sealed class BufferIf(IObservable> source, IObservable { private readonly IObservable _pauseIfTrueSelector = pauseIfTrueSelector ?? throw new ArgumentNullException(nameof(pauseIfTrueSelector)); - private readonly IScheduler _scheduler = scheduler ?? Scheduler.Default; + private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/List/Internal/FilterOnObservable.cs b/src/DynamicData/List/Internal/FilterOnObservable.cs index 3ee229a38..506079e9f 100644 --- a/src/DynamicData/List/Internal/FilterOnObservable.cs +++ b/src/DynamicData/List/Internal/FilterOnObservable.cs @@ -5,6 +5,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; +using DynamicData.Internal; namespace DynamicData.List.Internal; @@ -31,7 +32,7 @@ public IObservable> Run() => Observable.Create new[] { t }) : - itemHasChanged.Buffer(buffer.Value, scheduler ?? Scheduler.Default).Where(list => list.Count > 0); + itemHasChanged.Buffer(buffer.Value, scheduler ?? Defaults.Scheduler).Where(list => list.Count > 0); var requiresRefresh = itemsChanged.Synchronize(locker).Select( items => // catch all the indices of items which have been refreshed diff --git a/src/DynamicData/List/Internal/GroupOnProperty.cs b/src/DynamicData/List/Internal/GroupOnProperty.cs index 012800aa6..7a4700fb0 100644 --- a/src/DynamicData/List/Internal/GroupOnProperty.cs +++ b/src/DynamicData/List/Internal/GroupOnProperty.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; - +using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.List.Internal; @@ -27,7 +27,7 @@ public IObservable>> Run() => _source.Publish // add a throttle if specified if (throttle is not null) { - regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Scheduler.Default); + regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Defaults.Scheduler); } // Use property changes as a trigger to re-evaluate Grouping diff --git a/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs b/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs index fc1530a22..fb56b26e3 100644 --- a/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs +++ b/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; - +using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.List.Internal; @@ -27,7 +27,7 @@ public IObservable>> Run() => _source.Publ // add a throttle if specified if (throttle is not null) { - regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Scheduler.Default); + regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Defaults.Scheduler); } // Use property changes as a trigger to re-evaluate Grouping diff --git a/src/DynamicData/List/Internal/ToObservableChangeSet.cs b/src/DynamicData/List/Internal/ToObservableChangeSet.cs index 6f8c9152f..c04bc6ad2 100644 --- a/src/DynamicData/List/Internal/ToObservableChangeSet.cs +++ b/src/DynamicData/List/Internal/ToObservableChangeSet.cs @@ -6,6 +6,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; +using DynamicData.Internal; namespace DynamicData.List.Internal; @@ -25,7 +26,7 @@ public ToObservableChangeSet( { _expireAfter = expireAfter; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Scheduler.Default; + _scheduler = scheduler ?? Defaults.Scheduler; _source = Observable.Create>(observer => { @@ -51,7 +52,7 @@ public ToObservableChangeSet( { _expireAfter = expireAfter; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Scheduler.Default; + _scheduler = scheduler ?? Defaults.Scheduler; _source = source; } diff --git a/src/DynamicData/List/ObservableListEx.cs b/src/DynamicData/List/ObservableListEx.cs index 6dd83671e..b020f32f5 100644 --- a/src/DynamicData/List/ObservableListEx.cs +++ b/src/DynamicData/List/ObservableListEx.cs @@ -12,6 +12,7 @@ using DynamicData.Binding; using DynamicData.Cache.Internal; +using DynamicData.Internal; using DynamicData.Kernel; using DynamicData.List.Internal; using DynamicData.List.Linq; @@ -184,7 +185,7 @@ public static IObservable> AutoRefresh(this IObserv return t.WhenAnyPropertyChanged(); } - return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? Scheduler.Default); + return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? Defaults.Scheduler); }, changeSetBuffer, scheduler); @@ -215,7 +216,7 @@ public static IObservable> AutoRefresh(t return t.WhenPropertyChanged(propertyAccessor, false); } - return t.WhenPropertyChanged(propertyAccessor, false).Throttle(propertyChangeThrottle.Value, scheduler ?? Scheduler.Default); + return t.WhenPropertyChanged(propertyAccessor, false).Throttle(propertyChangeThrottle.Value, scheduler ?? Defaults.Scheduler); }, changeSetBuffer, scheduler); @@ -442,7 +443,7 @@ public static IObservable> BufferInitial(this IObse where TObject : notnull => source.DeferUntilLoaded().Publish( shared => { - var initial = shared.Buffer(initialBuffer, scheduler ?? Scheduler.Default).FlattenBufferResult().Take(1); + var initial = shared.Buffer(initialBuffer, scheduler ?? Defaults.Scheduler).FlattenBufferResult().Take(1); return initial.Concat(shared); }); @@ -679,7 +680,7 @@ public static IObservable> ExpireAfter(this ISourceList sou timeSelector.ThrowArgumentNullExceptionIfNull(nameof(timeSelector)); var locker = new object(); - var limiter = new ExpireAfter(source, timeSelector, pollingInterval, scheduler ?? Scheduler.Default, locker); + var limiter = new ExpireAfter(source, timeSelector, pollingInterval, scheduler ?? Defaults.Scheduler, locker); return limiter.Run().Synchronize(locker).Do(source.RemoveMany); } @@ -930,7 +931,7 @@ public static IObservable> LimitSizeTo(this ISourceList sou } var locker = new object(); - var limiter = new LimitSizeTo(source, sizeLimit, scheduler ?? Scheduler.Default, locker); + var limiter = new LimitSizeTo(source, sizeLimit, scheduler ?? Defaults.Scheduler, locker); return limiter.Run().Synchronize(locker).Do(source.RemoveMany); } From 971111c0950a4ac2d15478c62afaa1407f3a750e Mon Sep 17 00:00:00 2001 From: "Darrin W. Cullop" Date: Tue, 20 Feb 2024 10:59:49 -0800 Subject: [PATCH 2/3] Better naming --- src/DynamicData/Cache/Internal/AutoRefresh.cs | 3 +-- src/DynamicData/Cache/Internal/BatchIf.cs | 3 +-- .../Cache/Internal/GroupOnProperty.cs | 3 +-- .../GroupOnPropertyWithImmutableState.cs | 3 +-- .../Cache/Internal/ToObservableChangeSet.cs | 5 ++--- src/DynamicData/Cache/ObservableCacheEx.cs | 19 ++++++++++--------- .../Experimental/ExperimentalEx.cs | 3 +-- .../{Internal/Defaults.cs => GlobalConfig.cs} | 6 +++--- src/DynamicData/List/Internal/AutoRefresh.cs | 4 ++-- src/DynamicData/List/Internal/BufferIf.cs | 3 +-- .../List/Internal/FilterOnObservable.cs | 3 +-- .../List/Internal/GroupOnProperty.cs | 4 ++-- .../GroupOnPropertyWithImmutableState.cs | 4 ++-- .../List/Internal/ToObservableChangeSet.cs | 5 ++--- src/DynamicData/List/ObservableListEx.cs | 12 ++++++------ 15 files changed, 36 insertions(+), 44 deletions(-) rename src/DynamicData/{Internal/Defaults.cs => GlobalConfig.cs} (63%) diff --git a/src/DynamicData/Cache/Internal/AutoRefresh.cs b/src/DynamicData/Cache/Internal/AutoRefresh.cs index 04ea8eb82..a3f9a7fc1 100644 --- a/src/DynamicData/Cache/Internal/AutoRefresh.cs +++ b/src/DynamicData/Cache/Internal/AutoRefresh.cs @@ -5,7 +5,6 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; -using DynamicData.Internal; namespace DynamicData.Cache.Internal; @@ -15,7 +14,7 @@ internal sealed class AutoRefresh(IObservable> _reEvaluator = reEvaluator ?? throw new ArgumentNullException(nameof(reEvaluator)); - private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; + private readonly IScheduler _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/Cache/Internal/BatchIf.cs b/src/DynamicData/Cache/Internal/BatchIf.cs index 9907d3963..de70cf075 100644 --- a/src/DynamicData/Cache/Internal/BatchIf.cs +++ b/src/DynamicData/Cache/Internal/BatchIf.cs @@ -6,7 +6,6 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; -using DynamicData.Internal; namespace DynamicData.Cache.Internal; @@ -16,7 +15,7 @@ internal sealed class BatchIf(IObservable _pauseIfTrueSelector = pauseIfTrueSelector ?? throw new ArgumentNullException(nameof(pauseIfTrueSelector)); - private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; + private readonly IScheduler _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/Cache/Internal/GroupOnProperty.cs b/src/DynamicData/Cache/Internal/GroupOnProperty.cs index f189a935e..dc1b44a9a 100644 --- a/src/DynamicData/Cache/Internal/GroupOnProperty.cs +++ b/src/DynamicData/Cache/Internal/GroupOnProperty.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; -using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.Cache.Internal; @@ -28,7 +27,7 @@ public IObservable> Run() => _source.Publ // add a throttle if specified if (throttle is not null) { - regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Defaults.Scheduler); + regrouper = regrouper.Throttle(throttle.Value, scheduler ?? GlobalConfig.DefaultScheduler); } // Use property changes as a trigger to re-evaluate Grouping diff --git a/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs b/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs index 6c9cc9f3d..5ac4d5ac1 100644 --- a/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs +++ b/src/DynamicData/Cache/Internal/GroupOnPropertyWithImmutableState.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; -using DynamicData.Internal; using DynamicData.Kernel; namespace DynamicData.Cache.Internal; @@ -17,7 +16,7 @@ internal sealed class GroupOnPropertyWithImmutableState(I where TGroup : notnull { private readonly Func _groupSelector = groupSelectorKey.Compile(); - private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; + private readonly IScheduler _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs b/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs index 893b6701b..f7e84a27d 100644 --- a/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs +++ b/src/DynamicData/Cache/Internal/ToObservableChangeSet.cs @@ -6,7 +6,6 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; -using DynamicData.Internal; namespace DynamicData.Cache.Internal; @@ -30,7 +29,7 @@ public ToObservableChangeSet( _expireAfter = expireAfter; _keySelector = keySelector; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Defaults.Scheduler; + _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; _source = Observable.Create>(observer => { @@ -58,7 +57,7 @@ public ToObservableChangeSet( _expireAfter = expireAfter; _keySelector = keySelector; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Defaults.Scheduler; + _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; _source = source; } diff --git a/src/DynamicData/Cache/ObservableCacheEx.cs b/src/DynamicData/Cache/ObservableCacheEx.cs index 92433c732..c593c2a85 100644 --- a/src/DynamicData/Cache/ObservableCacheEx.cs +++ b/src/DynamicData/Cache/ObservableCacheEx.cs @@ -12,6 +12,7 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using System.Runtime.CompilerServices; +using DynamicData; using DynamicData.Binding; using DynamicData.Cache; using DynamicData.Cache.Internal; @@ -325,7 +326,7 @@ public static IObservable> AutoRefresh( return t.WhenAnyPropertyChanged(); } - return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? Defaults.Scheduler); + return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? GlobalConfig.DefaultScheduler); }, changeSetBuffer, scheduler); @@ -357,7 +358,7 @@ public static IObservable> AutoRefresh> Batch(this I { source.ThrowArgumentNullExceptionIfNull(nameof(source)); - return source.Buffer(timeSpan, scheduler ?? Defaults.Scheduler).FlattenBufferResult(); + return source.Buffer(timeSpan, scheduler ?? GlobalConfig.DefaultScheduler).FlattenBufferResult(); } /// @@ -833,7 +834,7 @@ public static IObservable> BufferInitial source.DeferUntilLoaded().Publish( shared => { - var initial = shared.Buffer(initialBuffer, scheduler ?? Defaults.Scheduler).FlattenBufferResult().Take(1); + var initial = shared.Buffer(initialBuffer, scheduler ?? GlobalConfig.DefaultScheduler).FlattenBufferResult().Take(1); return initial.Concat(shared); }); @@ -1358,7 +1359,7 @@ public static IObservable> Except(this /// public static IObservable> ExpireAfter(this IObservable> source, Func timeSelector) where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, Defaults.Scheduler); + where TKey : notnull => ExpireAfter(source, timeSelector, GlobalConfig.DefaultScheduler); /// /// Automatically removes items from the stream after the time specified by @@ -1402,7 +1403,7 @@ public static IObservable> ExpireAfter( /// timeSelector. public static IObservable> ExpireAfter(this IObservable> source, Func timeSelector, TimeSpan? pollingInterval) where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, pollingInterval, Defaults.Scheduler); + where TKey : notnull => ExpireAfter(source, timeSelector, pollingInterval, GlobalConfig.DefaultScheduler); /// /// Automatically removes items from the stream on the next poll after the time specified by @@ -1464,7 +1465,7 @@ public static IObservable>> ExpireAfter< /// timeSelector. public static IObservable>> ExpireAfter(this ISourceCache source, Func timeSelector, TimeSpan? interval = null) where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, interval, Defaults.Scheduler); + where TKey : notnull => ExpireAfter(source, timeSelector, interval, GlobalConfig.DefaultScheduler); /// /// Ensures there are no duplicated keys in the observable changeset. @@ -1505,7 +1506,7 @@ public static IObservable>> ExpireAfter< source.ThrowArgumentNullExceptionIfNull(nameof(source)); timeSelector.ThrowArgumentNullExceptionIfNull(nameof(timeSelector)); - scheduler ??= Defaults.Scheduler; + scheduler ??= GlobalConfig.DefaultScheduler; return Observable.Create>>( observer => source.Connect().ForExpiry(timeSelector, pollingInterval, scheduler).Finally(observer.OnCompleted).Subscribe( @@ -2500,7 +2501,7 @@ public static IObservable>> LimitSizeTo< long orderItemWasAdded = -1; var sizeLimiter = new SizeLimiter(sizeLimit); - return source.Connect().Finally(observer.OnCompleted).ObserveOn(scheduler ?? Defaults.Scheduler).Transform((t, v) => new ExpirableItem(t, v, DateTime.Now, Interlocked.Increment(ref orderItemWasAdded))).Select(sizeLimiter.CloneAndReturnExpiredOnly).Where(expired => expired.Length != 0).Subscribe( + return source.Connect().Finally(observer.OnCompleted).ObserveOn(scheduler ?? GlobalConfig.DefaultScheduler).Transform((t, v) => new ExpirableItem(t, v, DateTime.Now, Interlocked.Increment(ref orderItemWasAdded))).Select(sizeLimiter.CloneAndReturnExpiredOnly).Where(expired => expired.Length != 0).Subscribe( toRemove => { try diff --git a/src/DynamicData/Experimental/ExperimentalEx.cs b/src/DynamicData/Experimental/ExperimentalEx.cs index 5fa1906a4..206d427f1 100644 --- a/src/DynamicData/Experimental/ExperimentalEx.cs +++ b/src/DynamicData/Experimental/ExperimentalEx.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for full license information. using System.Reactive.Concurrency; -using DynamicData.Internal; namespace DynamicData.Experimental; @@ -27,6 +26,6 @@ public static IWatcher AsWatcher(this IObservable< { source.ThrowArgumentNullExceptionIfNull(nameof(source)); - return new Watcher(source, scheduler ?? Defaults.Scheduler); + return new Watcher(source, scheduler ?? GlobalConfig.DefaultScheduler); } } diff --git a/src/DynamicData/Internal/Defaults.cs b/src/DynamicData/GlobalConfig.cs similarity index 63% rename from src/DynamicData/Internal/Defaults.cs rename to src/DynamicData/GlobalConfig.cs index 23fd87412..53d26d61e 100644 --- a/src/DynamicData/Internal/Defaults.cs +++ b/src/DynamicData/GlobalConfig.cs @@ -4,9 +4,9 @@ using System.Reactive.Concurrency; -namespace DynamicData.Internal; +namespace DynamicData; -internal static class Defaults +internal static class GlobalConfig { - public static IScheduler Scheduler { get; } = TaskPoolScheduler.Default; + public static IScheduler DefaultScheduler { get; } = TaskPoolScheduler.Default; } diff --git a/src/DynamicData/List/Internal/AutoRefresh.cs b/src/DynamicData/List/Internal/AutoRefresh.cs index 655733576..2304284f6 100644 --- a/src/DynamicData/List/Internal/AutoRefresh.cs +++ b/src/DynamicData/List/Internal/AutoRefresh.cs @@ -5,7 +5,7 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; -using DynamicData.Internal; + using DynamicData.Kernel; namespace DynamicData.List.Internal; @@ -32,7 +32,7 @@ public IObservable> Run() => Observable.Create> itemsChanged = buffer is null ? itemHasChanged.Select(t => new[] { t }) : - itemHasChanged.Buffer(buffer.Value, scheduler ?? Defaults.Scheduler).Where(list => list.Count > 0); + itemHasChanged.Buffer(buffer.Value, scheduler ?? GlobalConfig.DefaultScheduler).Where(list => list.Count > 0); IObservable> requiresRefresh = itemsChanged.Synchronize(locker).Select( items => // catch all the indices of items which have been refreshed diff --git a/src/DynamicData/List/Internal/BufferIf.cs b/src/DynamicData/List/Internal/BufferIf.cs index ff394993e..2da8157f9 100644 --- a/src/DynamicData/List/Internal/BufferIf.cs +++ b/src/DynamicData/List/Internal/BufferIf.cs @@ -6,7 +6,6 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using System.Reactive.Subjects; -using DynamicData.Internal; namespace DynamicData.List.Internal; @@ -15,7 +14,7 @@ internal sealed class BufferIf(IObservable> source, IObservable { private readonly IObservable _pauseIfTrueSelector = pauseIfTrueSelector ?? throw new ArgumentNullException(nameof(pauseIfTrueSelector)); - private readonly IScheduler _scheduler = scheduler ?? Defaults.Scheduler; + private readonly IScheduler _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; private readonly IObservable> _source = source ?? throw new ArgumentNullException(nameof(source)); diff --git a/src/DynamicData/List/Internal/FilterOnObservable.cs b/src/DynamicData/List/Internal/FilterOnObservable.cs index 506079e9f..30c70843d 100644 --- a/src/DynamicData/List/Internal/FilterOnObservable.cs +++ b/src/DynamicData/List/Internal/FilterOnObservable.cs @@ -5,7 +5,6 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; -using DynamicData.Internal; namespace DynamicData.List.Internal; @@ -32,7 +31,7 @@ public IObservable> Run() => Observable.Create new[] { t }) : - itemHasChanged.Buffer(buffer.Value, scheduler ?? Defaults.Scheduler).Where(list => list.Count > 0); + itemHasChanged.Buffer(buffer.Value, scheduler ?? GlobalConfig.DefaultScheduler).Where(list => list.Count > 0); var requiresRefresh = itemsChanged.Synchronize(locker).Select( items => // catch all the indices of items which have been refreshed diff --git a/src/DynamicData/List/Internal/GroupOnProperty.cs b/src/DynamicData/List/Internal/GroupOnProperty.cs index 7a4700fb0..b98a5b7d9 100644 --- a/src/DynamicData/List/Internal/GroupOnProperty.cs +++ b/src/DynamicData/List/Internal/GroupOnProperty.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; -using DynamicData.Internal; + using DynamicData.Kernel; namespace DynamicData.List.Internal; @@ -27,7 +27,7 @@ public IObservable>> Run() => _source.Publish // add a throttle if specified if (throttle is not null) { - regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Defaults.Scheduler); + regrouper = regrouper.Throttle(throttle.Value, scheduler ?? GlobalConfig.DefaultScheduler); } // Use property changes as a trigger to re-evaluate Grouping diff --git a/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs b/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs index fb56b26e3..c85e9731f 100644 --- a/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs +++ b/src/DynamicData/List/Internal/GroupOnPropertyWithImmutableState.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; -using DynamicData.Internal; + using DynamicData.Kernel; namespace DynamicData.List.Internal; @@ -27,7 +27,7 @@ public IObservable>> Run() => _source.Publ // add a throttle if specified if (throttle is not null) { - regrouper = regrouper.Throttle(throttle.Value, scheduler ?? Defaults.Scheduler); + regrouper = regrouper.Throttle(throttle.Value, scheduler ?? GlobalConfig.DefaultScheduler); } // Use property changes as a trigger to re-evaluate Grouping diff --git a/src/DynamicData/List/Internal/ToObservableChangeSet.cs b/src/DynamicData/List/Internal/ToObservableChangeSet.cs index c04bc6ad2..50cd11c85 100644 --- a/src/DynamicData/List/Internal/ToObservableChangeSet.cs +++ b/src/DynamicData/List/Internal/ToObservableChangeSet.cs @@ -6,7 +6,6 @@ using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Reactive.Linq; -using DynamicData.Internal; namespace DynamicData.List.Internal; @@ -26,7 +25,7 @@ public ToObservableChangeSet( { _expireAfter = expireAfter; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Defaults.Scheduler; + _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; _source = Observable.Create>(observer => { @@ -52,7 +51,7 @@ public ToObservableChangeSet( { _expireAfter = expireAfter; _limitSizeTo = limitSizeTo; - _scheduler = scheduler ?? Defaults.Scheduler; + _scheduler = scheduler ?? GlobalConfig.DefaultScheduler; _source = source; } diff --git a/src/DynamicData/List/ObservableListEx.cs b/src/DynamicData/List/ObservableListEx.cs index b020f32f5..cca8351f1 100644 --- a/src/DynamicData/List/ObservableListEx.cs +++ b/src/DynamicData/List/ObservableListEx.cs @@ -10,9 +10,9 @@ using System.Reactive.Disposables; using System.Reactive.Linq; +using DynamicData; using DynamicData.Binding; using DynamicData.Cache.Internal; -using DynamicData.Internal; using DynamicData.Kernel; using DynamicData.List.Internal; using DynamicData.List.Linq; @@ -185,7 +185,7 @@ public static IObservable> AutoRefresh(this IObserv return t.WhenAnyPropertyChanged(); } - return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? Defaults.Scheduler); + return t.WhenAnyPropertyChanged().Throttle(propertyChangeThrottle.Value, scheduler ?? GlobalConfig.DefaultScheduler); }, changeSetBuffer, scheduler); @@ -216,7 +216,7 @@ public static IObservable> AutoRefresh(t return t.WhenPropertyChanged(propertyAccessor, false); } - return t.WhenPropertyChanged(propertyAccessor, false).Throttle(propertyChangeThrottle.Value, scheduler ?? Defaults.Scheduler); + return t.WhenPropertyChanged(propertyAccessor, false).Throttle(propertyChangeThrottle.Value, scheduler ?? GlobalConfig.DefaultScheduler); }, changeSetBuffer, scheduler); @@ -443,7 +443,7 @@ public static IObservable> BufferInitial(this IObse where TObject : notnull => source.DeferUntilLoaded().Publish( shared => { - var initial = shared.Buffer(initialBuffer, scheduler ?? Defaults.Scheduler).FlattenBufferResult().Take(1); + var initial = shared.Buffer(initialBuffer, scheduler ?? GlobalConfig.DefaultScheduler).FlattenBufferResult().Take(1); return initial.Concat(shared); }); @@ -680,7 +680,7 @@ public static IObservable> ExpireAfter(this ISourceList sou timeSelector.ThrowArgumentNullExceptionIfNull(nameof(timeSelector)); var locker = new object(); - var limiter = new ExpireAfter(source, timeSelector, pollingInterval, scheduler ?? Defaults.Scheduler, locker); + var limiter = new ExpireAfter(source, timeSelector, pollingInterval, scheduler ?? GlobalConfig.DefaultScheduler, locker); return limiter.Run().Synchronize(locker).Do(source.RemoveMany); } @@ -931,7 +931,7 @@ public static IObservable> LimitSizeTo(this ISourceList sou } var locker = new object(); - var limiter = new LimitSizeTo(source, sizeLimit, scheduler ?? Defaults.Scheduler, locker); + var limiter = new LimitSizeTo(source, sizeLimit, scheduler ?? GlobalConfig.DefaultScheduler, locker); return limiter.Run().Synchronize(locker).Do(source.RemoveMany); } From b375de9f75a481ce6090a1b311d5d6ef771fabc8 Mon Sep 17 00:00:00 2001 From: "Darrin W. Cullop" Date: Tue, 20 Feb 2024 11:31:11 -0800 Subject: [PATCH 3/3] Update GlobalConfig.cs --- src/DynamicData/GlobalConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamicData/GlobalConfig.cs b/src/DynamicData/GlobalConfig.cs index 53d26d61e..56916acb6 100644 --- a/src/DynamicData/GlobalConfig.cs +++ b/src/DynamicData/GlobalConfig.cs @@ -8,5 +8,5 @@ namespace DynamicData; internal static class GlobalConfig { - public static IScheduler DefaultScheduler { get; } = TaskPoolScheduler.Default; + public static IScheduler DefaultScheduler => TaskPoolScheduler.Default; }