You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
680 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Net3_Proxy
  7. {
  8. public static class TaskEx6
  9. {
  10. public static Task<TResult> FromException<TResult>(Exception exception)
  11. {
  12. if (exception == null) throw new ArgumentNullException(nameof(exception));
  13. var tcs = new TaskCompletionSource<TResult>();
  14. tcs.TrySetException(exception);
  15. return tcs.Task;
  16. }
  17. public static Task FromException(Exception exception) => FromException<VoidTaskResult>(exception);
  18. private struct VoidTaskResult { }
  19. }
  20. }