Skip to content

Commit

Permalink
Merge pull request #33 from mewlist/whenall-util
Browse files Browse the repository at this point in the history
Add WhenAll() utility
  • Loading branch information
mewlist authored May 22, 2024
2 parents b9885b4 + 065d485 commit 5f7a0ad
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Runtime/Helpers/TaskHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

#if USE_UNITASK
using Cysharp.Threading.Tasks;
Expand All @@ -21,5 +23,19 @@ public static async Task NextFrame(CancellationToken ct = default)
await TaskHelperInternal.NextFrame(ct);
}
#endif

public static async ValueTask<T[]> WhenAll<T>(params ValueTask<T>[] tasks)
{
var results = new T[tasks.Length];
for (var i = 0; i < tasks.Length; i++)
results[i] = await tasks[i].ConfigureAwait(false);
return results;
}

public static async ValueTask WhenAll(params ValueTask[] tasks)
{
foreach (var t in tasks)
await t.ConfigureAwait(false);
}
}
}

0 comments on commit 5f7a0ad

Please sign in to comment.