// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license 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() { return PlatformEnlightenmentProvider.Current.GetService() ?? new DefaultConcurrencyAbstractionLayer(); } } /// /// (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); } }