protected virtual void CancelCompletionSourceIfNecessary() { var task = CompletionSource?.Task; if (task == null || task.IsFaulted || task.IsCompleted || task.IsCanceled) { return; } CompletionSource.SetCanceled(); }
/// <summary> /// Marks the <see cref="Task{TResult}"/> that invocations will receive as canceled. /// </summary> public void SetCanceled() => CompletionSource.SetCanceled();