Table of Contents

Task.WhenEach for Unity / .NET Standard 2.1

Runtime/Threading/WhenEachEnumerator.cs   HeaderDoc

(c) 2025 Sator Imaging, Licensed under the MIT License https://github.com/sator-imaging/Unity-Fundamentals

How to Use

await foreach (var task in tasks.WhenEach())
{
    // do something for completed task
}

// for efficiency, cancellation token should be passed to WhenEach() directly.
// note that cancellation affects only on enumeration.
// jobs may continue running if those are depending on different token.
await foreach (var task in tasks.WhenEach(ct)) { }

// WithCancellation() creates new struct so a little bit inefficient.
await foreach (var task in tasks.WhenEach().WithCancellation(ct)) { }