diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs index a23d8413b0..ea42fa2ad7 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs @@ -57,7 +57,7 @@ private static TimeSpan Time /// [Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Now marked as obsolete.")] [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete(Constants_Core.OBSOLETE_SCHEDULEREQUIRED)] // Preferring static method call over instance method call. + [Obsolete(Constants_Core.ObsoleteSchedulerequired)] // Preferring static method call over instance method call. public bool ScheduleRequired => IsScheduleRequired; /// diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/DisableOptimizationsScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/DisableOptimizationsScheduler.cs index 8cb99c7cfe..1980aed0bc 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/DisableOptimizationsScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/DisableOptimizationsScheduler.cs @@ -14,7 +14,7 @@ internal sealed class DisableOptimizationsScheduler : SchedulerWrapper public DisableOptimizationsScheduler(IScheduler scheduler) : base(scheduler) { - _optimizationInterfaces = Scheduler.OPTIMIZATIONS; + _optimizationInterfaces = Scheduler.Optimizations; } public DisableOptimizationsScheduler(IScheduler scheduler, Type[] optimizationInterfaces) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs index e637405744..250a87747f 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs @@ -61,7 +61,7 @@ public partial class LocalScheduler /// Threshold where an item is considered to be short term work or gets moved from /// long term to short term. /// - private static readonly TimeSpan SHORTTERM = TimeSpan.FromSeconds(10); + private static readonly TimeSpan ShortTerm = TimeSpan.FromSeconds(10); /// /// Maximum error ratio for timer drift. We've seen machines with 10s drift on a @@ -79,14 +79,14 @@ public partial class LocalScheduler /// enough time to transition work to short term and as a courtesy to the /// destination scheduler to manage its queues etc. /// - private const int MAXERRORRATIO = 1000; + private const int MaxErrorRatio = 1000; /// /// Minimum threshold for the long term timer to fire before the queue is reevaluated /// for short term work. This value is chosen to be less than SHORTTERM in order to /// ensure the timer fires and has work to transition to the short term queue. /// - private static readonly TimeSpan LONGTOSHORT = TimeSpan.FromSeconds(5); + private static readonly TimeSpan LongToShort = TimeSpan.FromSeconds(5); /// /// Threshold used to determine when a short term timer has fired too early compared @@ -94,12 +94,12 @@ public partial class LocalScheduler /// completion of scheduled work, which can happen in case of time adjustment in the /// operating system (cf. GetSystemTimeAdjustment). /// - private static readonly TimeSpan RETRYSHORT = TimeSpan.FromMilliseconds(50); + private static readonly TimeSpan RetryShort = TimeSpan.FromMilliseconds(50); /// /// Longest interval supported by timers in the BCL. /// - private static readonly TimeSpan MAXSUPPORTEDTIMER = TimeSpan.FromMilliseconds((1L << 32) - 2); + private static readonly TimeSpan MaxSupportedTimer = TimeSpan.FromMilliseconds((1L << 32) - 2); /// /// Creates a new local scheduler. @@ -153,7 +153,7 @@ private IDisposable Enqueue(TState state, DateTimeOffset dueTime, Func(this, state, dueTime, action); - if (due <= SHORTTERM) + if (due <= ShortTerm) { ScheduleShortTermWork(workItem); } @@ -242,7 +242,7 @@ private IDisposable ExecuteNextShortTermWorkItem(IScheduler scheduler, IDisposab // have only "little" impact (range of 100s of ms). On an absolute time scale, we // don't provide stronger guarantees. // - if (next.DueTime - next.Scheduler.Now >= RETRYSHORT) + if (next.DueTime - next.Scheduler.Now >= RetryShort) { ScheduleShortTermWork(next); } @@ -324,13 +324,13 @@ private static void UpdateLongTermProcessingTimer() // error due to drift is negligible. // var due = Scheduler.Normalize(next.DueTime - next.Scheduler.Now); - var remainder = TimeSpan.FromTicks(Math.Max(due.Ticks / MAXERRORRATIO, LONGTOSHORT.Ticks)); + var remainder = TimeSpan.FromTicks(Math.Max(due.Ticks / MaxErrorRatio, LongToShort.Ticks)); var dueEarly = due - remainder; // // Limit the interval to maximum supported by underlying Timer. // - var dueCapped = TimeSpan.FromTicks(Math.Min(dueEarly.Ticks, MAXSUPPORTEDTIMER.Ticks)); + var dueCapped = TimeSpan.FromTicks(Math.Min(dueEarly.Ticks, MaxSupportedTimer.Ticks)); _nextLongTermWorkItem = next; _nextLongTermTimer.Disposable = ConcurrencyAbstractionLayer.Current.StartTimer(_ => EvaluateLongTermQueue(), null, dueCapped); @@ -352,7 +352,7 @@ private static void EvaluateLongTermQueue() next = _longTerm.Peek(); var due = Scheduler.Normalize(next.DueTime - next.Scheduler.Now); - if (due >= SHORTTERM) + if (due >= ShortTerm) { break; } diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs index 403596edd7..a8ba479125 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs @@ -330,7 +330,7 @@ public SchedulePeriodicStopwatch(IScheduler scheduler, TState state, TimeSpan pe _stopwatchProvider = stopwatchProvider; _state = state; - _runState = STOPPED; + _runState = Stopped; } private TState _state; @@ -362,10 +362,10 @@ public SchedulePeriodicStopwatch(IScheduler scheduler, TState state, TimeSpan pe // (d) Dispose returned object from Start --> scheduled work is cancelled // (e) Dispose returned object from Start --> unblocks _resumeEvent, Tick exits // - private const int STOPPED = 0; - private const int RUNNING = 1; - private const int SUSPENDED = 2; - private const int DISPOSED = 3; + private const int Stopped = 0; + private const int Running = 1; + private const int Suspended = 2; + private const int Disposed = 3; private IDisposable _task; @@ -375,7 +375,7 @@ public IDisposable Start() _stopwatch = _stopwatchProvider.StartStopwatch(); _nextDue = _period; - _runState = RUNNING; + _runState = Running; Disposable.TrySetSingle(ref _task, _scheduler.Schedule(this, _nextDue, (@this, a) => @this.Tick(a))); return this; @@ -398,7 +398,7 @@ private void Tick(Action, TimeSpan> recurse) { lock (_gate) { - if (_runState == RUNNING) + if (_runState == Running) { // // This is the fast path. We just let the stopwatch continue to @@ -410,7 +410,7 @@ private void Tick(Action, TimeSpan> recurse) break; } - if (_runState == DISPOSED) + if (_runState == Disposed) { // // In case the periodic job gets disposed but we are currently @@ -427,7 +427,7 @@ private void Tick(Action, TimeSpan> recurse) // to block such that future reevaluations of the next due time // will pick up the cumulative inactive time delta. // - Debug.Assert(_runState == SUSPENDED); + Debug.Assert(_runState == Suspended); } // @@ -449,7 +449,7 @@ private void Cancel() lock (_gate) { - _runState = DISPOSED; + _runState = Disposed; if (!Environment.HasShutdownStarted) { @@ -476,10 +476,10 @@ private void Suspending(object sender, HostSuspendingEventArgs args) // lock (_gate) { - if (_runState == RUNNING) + if (_runState == Running) { _suspendedAt = _stopwatch.Elapsed; - _runState = SUSPENDED; + _runState = Suspended; if (!Environment.HasShutdownStarted) { @@ -510,10 +510,10 @@ private void Resuming(object sender, HostResumingEventArgs args) // lock (_gate) { - if (_runState == SUSPENDED) + if (_runState == Suspended) { _inactiveTime += _stopwatch.Elapsed - _suspendedAt; - _runState = RUNNING; + _runState = Running; if (!Environment.HasShutdownStarted) { @@ -573,8 +573,8 @@ public IDisposable Start() // The protocol using the three commands is explained in the Tick implementation below. // private const int TICK = 0; - private const int DISPATCH_START = 1; - private const int DISPATCH_END = 2; + private const int DispatchStart = 1; + private const int DispatchEnd = 2; private void Tick(int command, Action recurse) { @@ -596,12 +596,12 @@ private void Tick(int command, Action recurse) // if (Interlocked.Increment(ref _pendingTickCount) == 1) { - goto case DISPATCH_START; + goto case DispatchStart; } break; - case DISPATCH_START: + case DispatchStart: try { _state = _action(_state); @@ -625,11 +625,11 @@ private void Tick(int command, Action recurse) // disabled using DisableOptimizations; legacy implementations of schedulers // from the v1.x days will not have a stopwatch). // - recurse(DISPATCH_END, TimeSpan.Zero); + recurse(DispatchEnd, TimeSpan.Zero); break; - case DISPATCH_END: + case DispatchEnd: // // If work was due while we were still running user code, the count will have // been incremented by the periodic tick handler above. In that case, we will @@ -642,7 +642,7 @@ private void Tick(int command, Action recurse) // if (Interlocked.Decrement(ref _pendingTickCount) > 0) { - recurse(DISPATCH_START, TimeSpan.Zero); + recurse(DispatchStart, TimeSpan.Zero); } break; diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs index f4e2b325de..3df4abb91c 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs @@ -10,7 +10,7 @@ namespace System.Reactive.Concurrency // public static partial class Scheduler { - internal static Type[] OPTIMIZATIONS = { + internal static Type[] Optimizations = { typeof(ISchedulerLongRunning), typeof(IStopwatchProvider), typeof(ISchedulerPeriodic) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs index 48998d39f8..992a69a692 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs @@ -65,7 +65,7 @@ public static partial class Scheduler /// /// Gets a scheduler that schedules work on the thread pool. /// - [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_THREADPOOL)] + [Obsolete(Constants_Core.ObsoleteSchedulerThreadpool)] public static IScheduler ThreadPool => _threadPool.Value; private static readonly Lazy _newThread = new Lazy(() => Initialize("NewThread")); @@ -73,7 +73,7 @@ public static partial class Scheduler /// /// Gets a scheduler that schedules work on a new thread using default thread creation options. /// - [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_NEWTHREAD)] + [Obsolete(Constants_Core.ObsoleteSchedulerNewthread)] public static IScheduler NewThread => _newThread.Value; private static readonly Lazy _taskPool = new Lazy(() => Initialize("TaskPool")); @@ -81,7 +81,7 @@ public static partial class Scheduler /// /// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler. /// - [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_TASKPOOL)] + [Obsolete(Constants_Core.ObsoleteSchedulerTaskpool)] public static IScheduler TaskPool => _taskPool.Value; private static IScheduler Initialize(string name) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs index 3145083b02..9dcb117d1f 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs @@ -9,18 +9,18 @@ namespace System.Reactive.Concurrency { internal static class TaskHelpers { - private const int MAX_DELAY = int.MaxValue; + private const int MaxDelay = int.MaxValue; public static Task Delay(TimeSpan delay, CancellationToken token) { var milliseconds = (long)delay.TotalMilliseconds; - if (milliseconds > MAX_DELAY) + if (milliseconds > MaxDelay) { - var remainder = delay - TimeSpan.FromMilliseconds(MAX_DELAY); + var remainder = delay - TimeSpan.FromMilliseconds(MaxDelay); return - Task.Delay(MAX_DELAY, token) + Task.Delay(MaxDelay, token) .ContinueWith(_ => Delay(remainder, token), TaskContinuationOptions.ExecuteSynchronously) .Unwrap(); } diff --git a/Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs b/Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs index a3212708f7..b1572151fb 100644 --- a/Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs +++ b/Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs @@ -18,11 +18,11 @@ public sealed class CompositeDisposable : ICollection, ICancelable private bool _disposed; private List _disposables; private int _count; - private const int SHRINK_THRESHOLD = 64; + private const int ShrinkThreshold = 64; // Default initial capacity of the _disposables list in case // The number of items is not known upfront - private const int DEFAULT_CAPACITY = 16; + private const int DefaultCapacity = 16; /// /// Initializes a new instance of the class with no disposables contained by it initially. @@ -85,7 +85,7 @@ public CompositeDisposable(IEnumerable disposables) else { // Unknown sized disposables, use the default capacity hint - Init(disposables, DEFAULT_CAPACITY); + Init(disposables, DefaultCapacity); } } @@ -190,7 +190,7 @@ public bool Remove(IDisposable item) current[i] = null; - if (current.Capacity > SHRINK_THRESHOLD && _count < current.Capacity / 2) + if (current.Capacity > ShrinkThreshold && _count < current.Capacity / 2) { var fresh = new List(current.Capacity / 2); @@ -357,7 +357,7 @@ public IEnumerator GetEnumerator() { if (_disposed || _count == 0) { - return EMPTY_ENUMERATOR; + return EmptyEnumerator; } // the copy is unavoidable but the creation // of an outer IEnumerable is avoidable @@ -380,7 +380,7 @@ public IEnumerator GetEnumerator() /// An empty enumerator for the /// method to avoid allocation on disposed or empty composites. /// - private static readonly CompositeEnumerator EMPTY_ENUMERATOR = + private static readonly CompositeEnumerator EmptyEnumerator = new CompositeEnumerator(new IDisposable[0]); /// diff --git a/Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs b/Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs index f0aa17f64e..844c4ea64f 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs @@ -11,9 +11,9 @@ internal sealed class CheckedObserver : IObserver private readonly IObserver _observer; private int _state; - private const int IDLE = 0; - private const int BUSY = 1; - private const int DONE = 2; + private const int Idle = 0; + private const int Busy = 1; + private const int Done = 2; public CheckedObserver(IObserver observer) { @@ -30,7 +30,7 @@ public void OnNext(T value) } finally { - Interlocked.Exchange(ref _state, IDLE); + Interlocked.Exchange(ref _state, Idle); } } @@ -44,7 +44,7 @@ public void OnError(Exception error) } finally { - Interlocked.Exchange(ref _state, DONE); + Interlocked.Exchange(ref _state, Done); } } @@ -58,17 +58,17 @@ public void OnCompleted() } finally { - Interlocked.Exchange(ref _state, DONE); + Interlocked.Exchange(ref _state, Done); } } private void CheckAccess() { - switch (Interlocked.CompareExchange(ref _state, BUSY, IDLE)) + switch (Interlocked.CompareExchange(ref _state, Busy, Idle)) { - case BUSY: + case Busy: throw new InvalidOperationException(Strings_Core.REENTRANCY_DETECTED); - case DONE: + case Done: throw new InvalidOperationException(Strings_Core.OBSERVER_TERMINATED); } } diff --git a/Rx.NET/Source/src/System.Reactive/Internal/Constants.cs b/Rx.NET/Source/src/System.Reactive/Internal/Constants.cs index a7c93521c1..ea6daa14c5 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/Constants.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/Constants.cs @@ -8,13 +8,13 @@ namespace System.Reactive internal static class Constants_Core { - private const string OBSOLETE_REFACTORING = "This property is no longer supported due to refactoring of the API surface and elimination of platform-specific dependencies."; + private const string ObsoleteRefactoring = "This property is no longer supported due to refactoring of the API surface and elimination of platform-specific dependencies."; - public const string OBSOLETE_SCHEDULER_NEWTHREAD = OBSOLETE_REFACTORING + " Please use NewThreadScheduler.Default to obtain an instance of this scheduler type."; - public const string OBSOLETE_SCHEDULER_TASKPOOL = OBSOLETE_REFACTORING + " Please use TaskPoolScheduler.Default to obtain an instance of this scheduler type."; - public const string OBSOLETE_SCHEDULER_THREADPOOL = OBSOLETE_REFACTORING + " Consider using Scheduler.Default to obtain the platform's most appropriate pool-based scheduler. In order to access a specific pool-based scheduler, please add a reference to the System.Reactive.PlatformServices assembly for your target platform and use the appropriate scheduler in the System.Reactive.Concurrency namespace."; + public const string ObsoleteSchedulerNewthread = ObsoleteRefactoring + " Please use NewThreadScheduler.Default to obtain an instance of this scheduler type."; + public const string ObsoleteSchedulerTaskpool = ObsoleteRefactoring + " Please use TaskPoolScheduler.Default to obtain an instance of this scheduler type."; + public const string ObsoleteSchedulerThreadpool = ObsoleteRefactoring + " Consider using Scheduler.Default to obtain the platform's most appropriate pool-based scheduler. In order to access a specific pool-based scheduler, please add a reference to the System.Reactive.PlatformServices assembly for your target platform and use the appropriate scheduler in the System.Reactive.Concurrency namespace."; - public const string OBSOLETE_SCHEDULEREQUIRED = "This instance property is no longer supported. Use CurrentThreadScheduler.IsScheduleRequired instead."; + public const string ObsoleteSchedulerequired = "This instance property is no longer supported. Use CurrentThreadScheduler.IsScheduleRequired instead."; } // We can't make those based on the Strings_*.resx file, because the ObsoleteAttribute needs a compile-time constant. @@ -22,8 +22,8 @@ internal static class Constants_Core internal static class Constants_Linq { #if PREFER_ASYNC - public const string USE_ASYNC = "This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block."; - public const string USE_TASK_FROMASYNCPATTERN = "This conversion is no longer supported. Replace use of the Begin/End asynchronous method pair with a new Task-based async method, and convert the result using ToObservable. If no Task-based async method is available, use Task.Factory.FromAsync to obtain a Task object."; + public const string UseAsync = "This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block."; + public const string UseTaskFromAsyncPattern = "This conversion is no longer supported. Replace use of the Begin/End asynchronous method pair with a new Task-based async method, and convert the result using ToObservable. If no Task-based async method is available, use Task.Factory.FromAsync to obtain a Task object."; #endif } } diff --git a/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs b/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs index 12461f27d6..b21892db34 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs @@ -14,10 +14,10 @@ namespace System.Reactive internal class ScheduledObserver : ObserverBase, IScheduledObserver { private int _state; - private const int STOPPED = 0; - private const int RUNNING = 1; - private const int PENDING = 2; - private const int FAULTED = 9; + private const int Stopped = 0; + private const int Running = 1; + private const int Pending = 2; + private const int Faulted = 9; private readonly ConcurrentQueue _queue = new ConcurrentQueue(); private bool _failed; private Exception _error; @@ -156,14 +156,14 @@ private void EnsureActiveSlow() while (true) { - var old = Interlocked.CompareExchange(ref _state, RUNNING, STOPPED); - if (old == STOPPED) + var old = Interlocked.CompareExchange(ref _state, Running, Stopped); + if (old == Stopped) { isOwner = true; // RUNNING break; } - if (old == FAULTED) + if (old == Faulted) { return; } @@ -191,7 +191,7 @@ private void EnsureActiveSlow() // should only be called after invocation of IObserver methods that touch // this state. // - if (old == PENDING || old == RUNNING && Interlocked.CompareExchange(ref _state, PENDING, RUNNING) == RUNNING) + if (old == Pending || old == Running && Interlocked.CompareExchange(ref _state, Pending, Running) == Running) { break; } @@ -229,7 +229,7 @@ private void Run(object state, Action recurse) continue; } - Interlocked.Exchange(ref _state, STOPPED); + Interlocked.Exchange(ref _state, Stopped); _observer.OnError(_error); Dispose(); return; @@ -256,26 +256,26 @@ private void Run(object state, Action recurse) continue; } - Interlocked.Exchange(ref _state, STOPPED); + Interlocked.Exchange(ref _state, Stopped); _observer.OnCompleted(); Dispose(); return; } - var old = Interlocked.CompareExchange(ref _state, STOPPED, RUNNING); - if (old == RUNNING || old == FAULTED) + var old = Interlocked.CompareExchange(ref _state, Stopped, Running); + if (old == Running || old == Faulted) { return; } - Debug.Assert(old == PENDING); + Debug.Assert(old == Pending); // The producer has put us in the PENDING state to prevent us from // transitioning to STOPPED, so we go RUNNING again and re-check our state. - _state = RUNNING; + _state = Running; } - Interlocked.Exchange(ref _state, RUNNING); + Interlocked.Exchange(ref _state, Running); try { @@ -283,7 +283,7 @@ private void Run(object state, Action recurse) } catch { - Interlocked.Exchange(ref _state, FAULTED); + Interlocked.Exchange(ref _state, Faulted); while (_queue.TryDequeue(out _)) { diff --git a/Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs b/Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs index 0ec7c1b361..e0f96648ff 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs @@ -24,10 +24,10 @@ public class DefaultSystemClock : ISystemClock internal class DefaultSystemClockMonitor : PeriodicTimerSystemClockMonitor { - private static readonly TimeSpan DEFAULT_PERIOD = TimeSpan.FromSeconds(1); + private static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(1); public DefaultSystemClockMonitor() - : base(DEFAULT_PERIOD) + : base(DefaultPeriod) { } } @@ -49,9 +49,9 @@ public class PeriodicTimerSystemClockMonitor : INotifySystemClockChanged private EventHandler _systemClockChanged; - private const int SYNC_MAXRETRIES = 100; - private const double SYNC_MAXDELTA = 10; - private const int MAXERROR = 100; + private const int SyncMaxRetries = 100; + private const double SyncMaxDelta = 10; + private const int MaxError = 100; /// /// Creates a new monitor for system clock changes with the specified polling frequency. @@ -94,7 +94,7 @@ private void NewTimer() Disposable.TrySetSerial(ref _timer, ConcurrencyAbstractionLayer.Current.StartPeriodicTimer(TimeChanged, _period)); - if (Math.Abs(SystemClock.UtcNow.ToUnixTimeMilliseconds() - now) <= SYNC_MAXDELTA) + if (Math.Abs(SystemClock.UtcNow.ToUnixTimeMilliseconds() - now) <= SyncMaxDelta) { break; } @@ -102,9 +102,9 @@ private void NewTimer() { break; } - if (++n >= SYNC_MAXRETRIES) + if (++n >= SyncMaxRetries) { - Task.Delay((int)SYNC_MAXDELTA).Wait(); + Task.Delay((int)SyncMaxDelta).Wait(); } }; } @@ -117,7 +117,7 @@ private void TimeChanged() var oldTime = (long)(last + _period.TotalMilliseconds); var diff = now - oldTime; - if (Math.Abs(diff) >= MAXERROR) + if (Math.Abs(diff) >= MaxError) { _systemClockChanged?.Invoke(this, new SystemClockChangedEventArgs( DateTimeOffset.FromUnixTimeMilliseconds(oldTime), newTime)); diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs index a094449066..a17d6ce55b 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs @@ -25,7 +25,7 @@ public static partial class Observable /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -53,7 +53,7 @@ public static Func> FromAsyncPattern(Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -82,7 +82,7 @@ public static Func> FromAsyncPattern /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -112,7 +112,7 @@ public static Func> FromAsyncPattern or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -143,7 +143,7 @@ public static Func> FromAsyncPattern or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -175,7 +175,7 @@ public static Func> FromAsyncPa /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -208,7 +208,7 @@ public static Func> From /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -242,7 +242,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -277,7 +277,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -313,7 +313,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -350,7 +350,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -388,7 +388,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -427,7 +427,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -467,7 +467,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -508,7 +508,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Func end) { @@ -538,7 +538,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -565,7 +565,7 @@ public static Func> FromAsyncPattern(Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -593,7 +593,7 @@ public static Func> FromAsyncPattern(Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -622,7 +622,7 @@ public static Func> FromAsyncPattern or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -652,7 +652,7 @@ public static Func> FromAsyncPattern or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -683,7 +683,7 @@ public static Func> FromAsyncPatte /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -715,7 +715,7 @@ public static Func> FromAsy /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -748,7 +748,7 @@ public static Func> /// or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -782,7 +782,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -817,7 +817,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -853,7 +853,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -890,7 +890,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -928,7 +928,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -967,7 +967,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { @@ -1007,7 +1007,7 @@ public static Func or is null. /// Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_TASK_FROMASYNCPATTERN)] + [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)] #endif public static Func> FromAsyncPattern(Func begin, Action end) { diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs index e36d342042..6b903d54c0 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs @@ -111,7 +111,7 @@ public static IEnumerable Collect(this IObservableThe source sequence is empty. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource First(this IObservable source) { @@ -134,7 +134,7 @@ public static TSource First(this IObservable source) /// No element satisfies the condition in the predicate. -or- The source sequence is empty. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource First(this IObservable source, Func predicate) { @@ -164,7 +164,7 @@ public static TSource First(this IObservable source, Func is null. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource FirstOrDefault(this IObservable source) { @@ -186,7 +186,7 @@ public static TSource FirstOrDefault(this IObservable source) /// or is null. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource FirstOrDefault(this IObservable source, Func predicate) { @@ -216,7 +216,7 @@ public static TSource FirstOrDefault(this IObservable source, /// or is null. /// Because of its blocking nature, this operator is mainly used for testing. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static void ForEach(this IObservable source, Action onNext) { @@ -242,7 +242,7 @@ public static void ForEach(this IObservable source, Action or is null. /// Because of its blocking nature, this operator is mainly used for testing. #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static void ForEach(this IObservable source, Action onNext) { @@ -294,7 +294,7 @@ public static IEnumerator GetEnumerator(this IObservableThe source sequence is empty. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource Last(this IObservable source) { @@ -317,7 +317,7 @@ public static TSource Last(this IObservable source) /// No element satisfies the condition in the predicate. -or- The source sequence is empty. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource Last(this IObservable source, Func predicate) { @@ -347,7 +347,7 @@ public static TSource Last(this IObservable source, Func is null. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource LastOrDefault(this IObservable source) { @@ -369,7 +369,7 @@ public static TSource LastOrDefault(this IObservable source) /// or is null. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource LastOrDefault(this IObservable source, Func predicate) { @@ -466,7 +466,7 @@ public static IEnumerable Next(this IObservable sourc /// The source sequence contains more than one element. -or- The source sequence is empty. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource Single(this IObservable source) { @@ -489,7 +489,7 @@ public static TSource Single(this IObservable source) /// No element satisfies the condition in the predicate. -or- More than one element satisfies the condition in the predicate. -or- The source sequence is empty. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource Single(this IObservable source, Func predicate) { @@ -520,7 +520,7 @@ public static TSource Single(this IObservable source, FuncThe source sequence contains more than one element. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource SingleOrDefault(this IObservable source) { @@ -543,7 +543,7 @@ public static TSource SingleOrDefault(this IObservable source) /// The sequence contains more than one element that satisfies the condition in the predicate. /// #if PREFER_ASYNC - [Obsolete(Constants_Linq.USE_ASYNC)] + [Obsolete(Constants_Linq.UseAsync)] #endif public static TSource SingleOrDefault(this IObservable source, Func predicate) { diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/GroupByUntil.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/GroupByUntil.cs index 56a8f342bb..534b6899bb 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/GroupByUntil.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/GroupByUntil.cs @@ -297,9 +297,9 @@ internal sealed class Map // and blocking, but also the more expensive operations that require all locks become (e.g. table // resizing, ToArray, Count, etc). According to brief benchmarks that we ran, 4 seems like a good // compromise. - private const int DEFAULT_CONCURRENCY_MULTIPLIER = 4; + private const int DefaultConcurrencyMultiplier = 4; - private static int DefaultConcurrencyLevel => DEFAULT_CONCURRENCY_MULTIPLIER * Environment.ProcessorCount; + private static int DefaultConcurrencyLevel => DefaultConcurrencyMultiplier * Environment.ProcessorCount; private readonly ConcurrentDictionary _map; diff --git a/Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs b/Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs index b5bd8d9d95..0f5a38c4fa 100644 --- a/Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs +++ b/Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs @@ -25,17 +25,17 @@ public sealed class AsyncSubject : SubjectBase, INotifyCompletion /// /// A pre-allocated empty array for the no-observers state. /// - private static readonly AsyncSubjectDisposable[] EMPTY = new AsyncSubjectDisposable[0]; + private static readonly AsyncSubjectDisposable[] Empty = new AsyncSubjectDisposable[0]; /// /// A pre-allocated empty array indicating the AsyncSubject has terminated /// - private static readonly AsyncSubjectDisposable[] TERMINATED = new AsyncSubjectDisposable[0]; + private static readonly AsyncSubjectDisposable[] Terminated = new AsyncSubjectDisposable[0]; /// /// A pre-allocated empty array indicating the AsyncSubject has terminated /// - private static readonly AsyncSubjectDisposable[] DISPOSED = new AsyncSubjectDisposable[0]; + private static readonly AsyncSubjectDisposable[] Disposed = new AsyncSubjectDisposable[0]; #endregion @@ -46,7 +46,7 @@ public sealed class AsyncSubject : SubjectBase, INotifyCompletion /// public AsyncSubject() { - _observers = EMPTY; + _observers = Empty; } #endregion @@ -61,7 +61,7 @@ public AsyncSubject() /// /// Indicates whether the subject has been disposed. /// - public override bool IsDisposed => Volatile.Read(ref _observers) == DISPOSED; + public override bool IsDisposed => Volatile.Read(ref _observers) == Disposed; #endregion @@ -77,17 +77,17 @@ public override void OnCompleted() for (; ; ) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _exception = null; ThrowDisposed(); break; } - if (observers == TERMINATED) + if (observers == Terminated) { break; } - if (Interlocked.CompareExchange(ref _observers, TERMINATED, observers) == observers) + if (Interlocked.CompareExchange(ref _observers, Terminated, observers) == observers) { var hasValue = _hasValue; if (hasValue) @@ -132,19 +132,19 @@ public override void OnError(Exception error) for (; ; ) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _exception = null; _value = default; ThrowDisposed(); break; } - if (observers == TERMINATED) + if (observers == Terminated) { break; } _exception = error; - if (Interlocked.CompareExchange(ref _observers, TERMINATED, observers) == observers) + if (Interlocked.CompareExchange(ref _observers, Terminated, observers) == observers) { foreach (var o in observers) { @@ -165,14 +165,14 @@ public override void OnError(Exception error) public override void OnNext(T value) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _value = default; _exception = null; ThrowDisposed(); return; } - if (observers == TERMINATED) + if (observers == Terminated) { return; } @@ -226,7 +226,7 @@ private bool Add(AsyncSubjectDisposable inner) for (; ; ) { var a = Volatile.Read(ref _observers); - if (a == DISPOSED) + if (a == Disposed) { _value = default; _exception = null; @@ -234,7 +234,7 @@ private bool Add(AsyncSubjectDisposable inner) return true; } - if (a == TERMINATED) + if (a == Terminated) { return false; } @@ -282,7 +282,7 @@ private void Remove(AsyncSubjectDisposable inner) var b = default(AsyncSubjectDisposable[]); if (n == 1) { - b = EMPTY; + b = Empty; } else { @@ -337,7 +337,7 @@ private void ThrowDisposed() /// public override void Dispose() { - if (Interlocked.Exchange(ref _observers, DISPOSED) != DISPOSED) + if (Interlocked.Exchange(ref _observers, Disposed) != Disposed) { _exception = null; _value = default; @@ -422,7 +422,7 @@ private void InvokeOnOriginalContext() /// /// Gets whether the AsyncSubject has completed. /// - public bool IsCompleted => Volatile.Read(ref _observers) == TERMINATED; + public bool IsCompleted => Volatile.Read(ref _observers) == Terminated; /// /// Gets the last element of the subject, potentially blocking until the subject completes successfully or exceptionally. @@ -432,7 +432,7 @@ private void InvokeOnOriginalContext() [Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Await pattern for C# and VB compilers.")] public T GetResult() { - if (Volatile.Read(ref _observers) != TERMINATED) + if (Volatile.Read(ref _observers) != Terminated) { var e = new ManualResetEvent(initialState: false); OnCompleted(() => e.Set(), originalContext: false); diff --git a/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs b/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs index 9f65d2aa27..3e3a863d53 100644 --- a/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs +++ b/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs @@ -18,9 +18,9 @@ public sealed class Subject : SubjectBase private SubjectDisposable[] _observers; private Exception _exception; - private static readonly SubjectDisposable[] EMPTY = new SubjectDisposable[0]; - private static readonly SubjectDisposable[] TERMINATED = new SubjectDisposable[0]; - private static readonly SubjectDisposable[] DISPOSED = new SubjectDisposable[0]; + private static readonly SubjectDisposable[] Empty = new SubjectDisposable[0]; + private static readonly SubjectDisposable[] Terminated = new SubjectDisposable[0]; + private static readonly SubjectDisposable[] Disposed = new SubjectDisposable[0]; #endregion @@ -31,7 +31,7 @@ public sealed class Subject : SubjectBase /// public Subject() { - Volatile.Write(ref _observers, EMPTY); + Volatile.Write(ref _observers, Empty); } #endregion @@ -52,7 +52,7 @@ public override bool HasObservers /// /// Indicates whether the subject has been disposed. /// - public override bool IsDisposed => Volatile.Read(ref _observers) == DISPOSED; + public override bool IsDisposed => Volatile.Read(ref _observers) == Disposed; #endregion @@ -73,17 +73,17 @@ public override void OnCompleted() for (; ; ) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _exception = null; ThrowDisposed(); break; } - if (observers == TERMINATED) + if (observers == Terminated) { break; } - if (Interlocked.CompareExchange(ref _observers, TERMINATED, observers) == observers) + if (Interlocked.CompareExchange(ref _observers, Terminated, observers) == observers) { foreach (var observer in observers) { @@ -109,18 +109,18 @@ public override void OnError(Exception error) for (; ; ) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _exception = null; ThrowDisposed(); break; } - if (observers == TERMINATED) + if (observers == Terminated) { break; } _exception = error; - if (Interlocked.CompareExchange(ref _observers, TERMINATED, observers) == observers) + if (Interlocked.CompareExchange(ref _observers, Terminated, observers) == observers) { foreach (var observer in observers) { @@ -138,7 +138,7 @@ public override void OnError(Exception error) public override void OnNext(T value) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _exception = null; ThrowDisposed(); @@ -171,13 +171,13 @@ public override IDisposable Subscribe(IObserver observer) for (; ; ) { var observers = Volatile.Read(ref _observers); - if (observers == DISPOSED) + if (observers == Disposed) { _exception = null; ThrowDisposed(); break; } - if (observers == TERMINATED) + if (observers == Terminated) { var ex = _exception; if (ex != null) @@ -229,7 +229,7 @@ private void Unsubscribe(SubjectDisposable observer) var b = default(SubjectDisposable[]); if (n == 1) { - b = EMPTY; + b = Empty; } else { @@ -279,7 +279,7 @@ public void Dispose() /// public override void Dispose() { - Interlocked.Exchange(ref _observers, DISPOSED); + Interlocked.Exchange(ref _observers, Disposed); _exception = null; }