internal sealed override TaskCompletionSource <int> FromResult(int result)
 {
     if (result < -1 || result >= 9)
     {
         return(AsyncMethodTaskCache <int> .CreateCompleted(result));
     }
     return(AsyncMethodTaskCache <TResult> .AsyncMethodInt32TaskCache.Int32Tasks[result - -1]);
 }
 private static TaskCompletionSource <int>[] CreateInt32Tasks()
 {
     TaskCompletionSource <int>[] array = new TaskCompletionSource <int> [10];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = AsyncMethodTaskCache <int> .CreateCompleted(i + -1);
     }
     return(array);
 }
 /// <summary>
 /// Gets a task for the specified result. This will either be a cached or new task, never
 /// <see langword="null"/>.
 /// </summary>
 /// <param name="result">The result for which we need a task.</param>
 /// <returns>The completed task containing the result.</returns>
 private TaskCompletionSource<TResult> GetTaskForResult(TResult result)
 {
     ////Contract.Ensures(
     ////   EqualityComparer<TResult>.Default.Equals(result, Contract.Result<Task<TResult>>().Result),
     ////    "The returned task's Result must return the same value as the specified result value.");
     var cache = AsyncMethodTaskCache<TResult>.Singleton;
     return cache != null ?
         cache.FromResult(result) :
         AsyncMethodTaskCache<TResult>.CreateCompleted(result);
 }
        /// <summary>
        /// Gets a task for the specified result. This will either be a cached or new task, never
        /// <see langword="null"/>.
        /// </summary>
        /// <param name="result">The result for which we need a task.</param>
        /// <returns>The completed task containing the result.</returns>
        private TaskCompletionSource <TResult> GetTaskForResult(TResult result)
        {
            AsyncMethodTaskCache <TResult> singleton = AsyncMethodTaskCache <TResult> .Singleton;

            if (singleton == null)
            {
                return(AsyncMethodTaskCache <TResult> .CreateCompleted(result));
            }

            return(singleton.FromResult(result));
        }
        /// <summary>Temporary support for disabling crashing if tasks go unobserved.</summary>
        static AsyncTaskMethodBuilder()
        {
            _defaultResultTask = AsyncMethodTaskCache <TResult> .CreateCompleted(default(TResult));

            try
            {
                AsyncVoidMethodBuilder.PreventUnobservedTaskExceptions();
            }
            catch
            {
            }
        }
 internal virtual TaskCompletionSource <TResult> FromResult(TResult result)
 {
     return(AsyncMethodTaskCache <TResult> .CreateCompleted(result));
 }