using System; using System.Threading.Tasks; namespace Swan { /// /// Provides extension methods for and . /// public static class TaskExtensions { /// /// Suspends execution until the specified is completed. /// This method operates similarly to the C# operator, /// but is meant to be called from a non- method. /// /// The on which this method is called. /// is . public static void Await(this Task @this) => @this.GetAwaiter().GetResult(); /// /// Suspends execution until the specified is completed /// and returns its result. /// This method operates similarly to the C# operator, /// but is meant to be called from a non- method. /// /// The type of the task's result. /// The on which this method is called. /// The result of . /// is . public static TResult Await(this Task @this) => @this.GetAwaiter().GetResult(); /// /// Suspends execution until the specified is completed. /// This method operates similarly to the C# operator, /// but is meant to be called from a non- method. /// /// The on which this method is called. /// If set to , /// attempts to marshal the continuation back to the original context captured. /// This parameter has the same effect as calling the /// method. /// is . public static void Await(this Task @this, Boolean continueOnCapturedContext) => @this.ConfigureAwait(continueOnCapturedContext).GetAwaiter().GetResult(); /// /// Suspends execution until the specified is completed /// and returns its result. /// This method operates similarly to the C# operator, /// but is meant to be called from a non- method. /// /// The type of the task's result. /// The on which this method is called. /// If set to , /// attempts to marshal the continuation back to the original context captured. /// This parameter has the same effect as calling the /// method. /// The result of . /// is . public static TResult Await(this Task @this, Boolean continueOnCapturedContext) => @this.ConfigureAwait(continueOnCapturedContext).GetAwaiter().GetResult(); } }