CTaskHelper.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections.Generic;
  2. namespace Fort23.Core
  3. {
  4. public static class CTaskHelper
  5. {
  6. // private class CoroutineBlocker
  7. // {
  8. // private int count;
  9. //
  10. // private List<CTask> tcss = new List<CTask>();
  11. //
  12. // public CoroutineBlocker(int count)
  13. // {
  14. // this.count = count;
  15. // }
  16. //
  17. // public async CTask WaitAsync()
  18. // {
  19. // --this.count;
  20. // if (this.count < 0)
  21. // {
  22. // return;
  23. // }
  24. //
  25. // if (this.count == 0)
  26. // {
  27. // List<CTask> t = this.tcss;
  28. // this.tcss = null;
  29. // foreach (CTask ttcs in t)
  30. // {
  31. // ttcs.SetResult();
  32. // }
  33. //
  34. // return;
  35. // }
  36. //
  37. // CTask tcs = CTask.Create();
  38. //
  39. // tcss.Add(tcs);
  40. // await tcs;
  41. // }
  42. // }
  43. // public static async CTask<bool> WaitAll<T>(List<CTask<T>> tasks)
  44. // {
  45. // if (tasks.Count == 0)
  46. // {
  47. // return false;
  48. // }
  49. //
  50. // CoroutineBlocker coroutineBlocker = new CoroutineBlocker(tasks.Count + 1);
  51. // foreach (CTask<T> task in tasks)
  52. // {
  53. // RunOneTask(task);
  54. // }
  55. //
  56. // async void RunOneTask(CTask<T> task)
  57. // {
  58. // await task;
  59. // await coroutineBlocker.WaitAsync();
  60. // }
  61. // await coroutineBlocker.WaitAsync();
  62. // return true;
  63. // }
  64. // public static async CTask<bool> WaitAll(List<CTask> tasks)
  65. // {
  66. // if (tasks.Count == 0)
  67. // {
  68. // return false;
  69. // }
  70. //
  71. // CoroutineBlocker coroutineBlocker = new CoroutineBlocker(tasks.Count + 1);
  72. // foreach (CTask task in tasks)
  73. // {
  74. // RunOneTask(task);
  75. //
  76. // }
  77. //
  78. // await coroutineBlocker.WaitAsync();
  79. //
  80. // async void RunOneTask(CTask task)
  81. // {
  82. // await task;
  83. // await coroutineBlocker.WaitAsync();
  84. // }
  85. // return true;
  86. // }
  87. }
  88. }