// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. // See the LICENSE file in the project root for more information. using System.ComponentModel; using System.Reactive.PlatformServices; namespace System.Reactive.Concurrency { /// /// (Infrastructure) Concurrency abstraction layer. /// internal static class ConcurrencyAbstractionLayer { /// /// Gets the current CAL. If no CAL has been set yet, it will be initialized to the default. /// public static IConcurrencyAbstractionLayer Current { get; } = Initialize(); private static IConcurrencyAbstractionLayer Initialize() { // // NB: For compat reasons, we allow null to leak here. Bad things will happen but we don't want // to trigger an exception earlier than we did before. The only case where this can happen // is when a custom PEP is installed, which is very rare (e.g. debugger, service hosting). // return PlatformEnlightenmentProvider.Current.GetService()!; } } /// /// (Infrastructure) Concurrency abstraction layer interface. /// /// /// This type is used by the Rx infrastructure and not meant for public consumption or implementation. /// No guarantees are made about forward compatibility of the type's functionality and its usage. /// [EditorBrowsable(EditorBrowsableState.Never)] public interface IConcurrencyAbstractionLayer { /// /// Queues a method for execution at the specified relative time. /// /// Method to execute. /// State to pass to the method. /// Time to execute the method on. /// Disposable object that can be used to stop the timer. IDisposable StartTimer(Action action, object? state, TimeSpan dueTime); /// /// Queues a method for periodic execution based on the specified period. /// /// Method to execute; should be safe for reentrancy. /// Period for running the method periodically. /// Disposable object that can be used to stop the timer. IDisposable StartPeriodicTimer(Action action, TimeSpan period); /// /// Queues a method for execution. /// /// Method to execute. /// State to pass to the method. /// Disposable object that can be used to cancel the queued method. IDisposable QueueUserWorkItem(Action action, object? state); /// /// Blocking sleep operation. /// /// Time to sleep. void Sleep(TimeSpan timeout); /// /// Starts a new stopwatch object. /// /// New stopwatch object; started at the time of the request. IStopwatch StartStopwatch(); /// /// Gets whether long-running scheduling is supported. /// bool SupportsLongRunning { get; } /// /// Starts a new long-running thread. /// /// Method to execute. /// State to pass to the method. void StartThread(Action action, object? state); } }