UniTaskExtensions.Shorthand.tt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <#@ template debug="false" hostspecific="false" language="C#" #>
  2. <#@ assembly name="System.Core" #>
  3. <#@ import namespace="System.Linq" #>
  4. <#@ import namespace="System.Text" #>
  5. <#@ import namespace="System.Collections.Generic" #>
  6. <#@ output extension=".cs" #>
  7. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  8. using System.Collections.Generic;
  9. namespace Cysharp.Threading.Tasks
  10. {
  11. public static partial class UniTaskExtensions
  12. {
  13. // shorthand of WhenAll
  14. public static UniTask.Awaiter GetAwaiter(this UniTask[] tasks)
  15. {
  16. return UniTask.WhenAll(tasks).GetAwaiter();
  17. }
  18. public static UniTask.Awaiter GetAwaiter(this IEnumerable<UniTask> tasks)
  19. {
  20. return UniTask.WhenAll(tasks).GetAwaiter();
  21. }
  22. public static UniTask<T[]>.Awaiter GetAwaiter<T>(this UniTask<T>[] tasks)
  23. {
  24. return UniTask.WhenAll(tasks).GetAwaiter();
  25. }
  26. public static UniTask<T[]>.Awaiter GetAwaiter<T>(this IEnumerable<UniTask<T>> tasks)
  27. {
  28. return UniTask.WhenAll(tasks).GetAwaiter();
  29. }
  30. <# for(var i = 2; i <= 15; i++ ) {
  31. var range = Enumerable.Range(1, i);
  32. var t = string.Join(", ", range.Select(x => "T" + x));
  33. var args = string.Join(", ", range.Select(x => $"UniTask<T{x}> task{x}"));
  34. var titems = string.Join(", ", range.Select(x => $"tasks.Item{x}"));
  35. #>
  36. public static UniTask<(<#= t #>)>.Awaiter GetAwaiter<<#= t #>>(this (<#= args #>) tasks)
  37. {
  38. return UniTask.WhenAll(<#= titems #>).GetAwaiter();
  39. }
  40. <# } #>
  41. <# for(var i = 2; i <= 15; i++ ) {
  42. var range = Enumerable.Range(1, i);
  43. var args = string.Join(", ", range.Select(x => $"UniTask task{x}"));
  44. var titems = string.Join(", ", range.Select(x => $"tasks.Item{x}"));
  45. #>
  46. public static UniTask.Awaiter GetAwaiter(this (<#= args #>) tasks)
  47. {
  48. return UniTask.WhenAll(<#= titems #>).GetAwaiter();
  49. }
  50. <# } #>
  51. }
  52. }