ActiveAsyncPlan.Generated.tt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. <#@ template debug="false" hostspecific="false" language="C#" #>
  5. <#@ assembly name="System.Core" #>
  6. <#@ import namespace="System.Linq" #>
  7. <#@ import namespace="System.Text" #>
  8. <#@ import namespace="System.Collections.Generic" #>
  9. <#@ output extension=".cs" #>
  10. using System.Threading.Tasks;
  11. namespace System.Reactive.Joins
  12. {
  13. <#
  14. for (var i = 1; i <= 16; i++)
  15. {
  16. var genArgs = string.Join(", ", Enumerable.Range(1, i).Select(j => "TSource" + j));
  17. var args = string.Join(", ", Enumerable.Range(1, i).Select(j => "IAsyncObservable<TSource" + j + "> source" + j));
  18. var observers = string.Join(", ", Enumerable.Range(1, i).Select(j => "AsyncJoinObserver<TSource" + j + "> observer" + j));
  19. #>
  20. internal sealed class ActiveAsyncPlan<<#=genArgs#>> : ActiveAsyncPlan
  21. {
  22. private readonly Func<<#=genArgs#>, Task> _onNext;
  23. private readonly Func<Task> _onCompleted;
  24. <#
  25. for (var j = 1; j <= i; j++)
  26. {
  27. #>
  28. private readonly AsyncJoinObserver<TSource<#=j#>> _observer<#=j#>;
  29. <#
  30. }
  31. #>
  32. internal ActiveAsyncPlan(<#=observers#>, Func<<#=genArgs#>, Task> onNext, Func<Task> onCompleted)
  33. {
  34. _onNext = onNext;
  35. _onCompleted = onCompleted;
  36. <#
  37. for (var j = 1; j <= i; j++)
  38. {
  39. #>
  40. _observer<#=j#> = observer<#=j#>;
  41. <#
  42. }
  43. #>
  44. <#
  45. for (var j = 1; j <= i; j++)
  46. {
  47. #>
  48. AddJoinObserver(observer<#=j#>);
  49. <#
  50. }
  51. #>
  52. }
  53. internal override Task Match()
  54. {
  55. if (<#=string.Join(" && ", Enumerable.Range(1, i).Select(j => "_observer" + j + ".Queue.Count > 0"))#>)
  56. {
  57. <#
  58. for (var j = 1; j <= i; j++)
  59. {
  60. #>
  61. var notification<#=j#> = _observer<#=j#>.Queue.Peek();
  62. <#
  63. }
  64. #>
  65. if (<#=string.Join(" || ", Enumerable.Range(1, i).Select(j => "notification" + j + ".Kind == NotificationKind.OnCompleted"))#>)
  66. {
  67. return _onCompleted();
  68. }
  69. Dequeue();
  70. return _onNext(<#=string.Join(", ", Enumerable.Range(1, i).Select(j => "notification" + j + ".Value"))#>);
  71. }
  72. return Task.CompletedTask;
  73. }
  74. }
  75. <#
  76. }
  77. #>
  78. }