TaskExt.cs 684 B

1234567891011121314151617181920
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. namespace System.Threading.Tasks
  6. {
  7. static class TaskExt
  8. {
  9. public static readonly Task<bool> True = Task.FromResult(true);
  10. public static readonly Task<bool> False = Task.FromResult(false);
  11. public static Task<T> Throw<T>(Exception exception)
  12. {
  13. var tcs = new TaskCompletionSource<T>();
  14. tcs.TrySetException(exception);
  15. return tcs.Task;
  16. }
  17. }
  18. }