public static ConfiguredValueTaskAwaitable EnsureCompleted(this ConfiguredValueTaskAwaitable awaitable, bool async) { if (!async) { #if DEBUG VerifyTaskCompleted(awaitable.GetAwaiter().IsCompleted); #endif } return(awaitable); }
public ConfiguredValueTaskAwaiterWrapper GetAwaiter() { return(new(_awaitable.GetAwaiter())); }
public WithCancellationValueTaskAwaiter <T> GetAwaiter() => new WithCancellationValueTaskAwaiter <T>(_awaitable.GetAwaiter(), _cancellationToken);
public static ConfiguredValueTaskAwaitable EnsureCompleted(this ConfiguredValueTaskAwaitable task, bool async) { Debug.Assert(async || task.GetAwaiter().IsCompleted); return(task); }
/// <summary> /// 结束对已完成任务的等待,并返回执行结果。 /// </summary> /// <typeparam name="TResult">指定的结果类型。</typeparam> /// <param name="awaitable">给定的 <see cref="ConfiguredValueTaskAwaitable" />。</param> /// <returns>返回 <typeparamref name="TResult"/>。</returns> public static TResult AwaitResult <TResult>(this ConfiguredValueTaskAwaitable <TResult> awaitable) => awaitable.GetAwaiter().GetResult();
=> task.ConfigureAwait(false); // .NET 默认调用 task.ConfigureAwait(true); #endregion #region ConfiguredValueTaskAwaitable /// <summary> /// 结束对已完成任务的等待。 /// </summary> /// <param name="awaitable">给定的 <see cref="ConfiguredValueTaskAwaitable" />。</param> public static void Await(this ConfiguredValueTaskAwaitable awaitable) => awaitable.GetAwaiter().GetResult();