Jo Shields 3c1f479b9d Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
2015-04-07 09:35:12 +01:00

30 lines
1.3 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="TaskExtensions.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Util {
using System;
using System.Threading.Tasks;
// Contains helper methods for dealing with Tasks
internal static class TaskExtensions {
// Throws the exception that faulted a Task, similar to what 'await' would have done.
// Useful for synchronous methods which have a Task instance they know to be already completed
// and where they want to let the exception propagate upward.
public static void ThrowIfFaulted(this Task task) {
Debug.Assert(task.IsCompleted, "The Task passed to this method must be marked as completed so that this method doesn't block.");
task.GetAwaiter().GetResult();
}
// Gets a WithinCancellableCallbackTaskAwaiter from a Task.
public static WithinCancellableCallbackTaskAwaitable WithinCancellableCallback(this Task task, HttpContext context) {
return new WithinCancellableCallbackTaskAwaitable(context, task.GetAwaiter());
}
}
}