// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #if !NO_TPL using System.ComponentModel; using System.Reactive.PlatformServices; using System.Threading; using System.Threading.Tasks; namespace System.Reactive { internal static class TaskHelpers { private static Lazy s_services = new Lazy(Initialize); private static ITaskServices Initialize() { return PlatformEnlightenmentProvider.Current.GetService() ?? new DefaultTaskServices(); } public static bool TrySetCanceled(this TaskCompletionSource tcs, CancellationToken token) { return s_services.Value.TrySetCanceled(tcs, token); } } } namespace System.Reactive.PlatformServices { /// /// (Infrastructure) Services to leverage evolving TPL Task APIs. /// /// /// 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 ITaskServices { /// /// Attempts to transition the underlying Task{T} into the Canceled state. /// /// Type of the result of the underlying task. /// Task completion source whose underlying task to transition into the Canceled state. /// Cancellation token that triggered the cancellation. /// True if the operation was successful; false if the operation was unsuccessful or the object has already been disposed. bool TrySetCanceled(TaskCompletionSource tcs, CancellationToken token); } } #endif