Created
January 2, 2023 22:48
-
-
Save kevingosse/d135acb9fb8424779084b080116fa2c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Task WhenAllOrFaulted(params Task[] tasks) | |
{ | |
var faultedContinuations = new Task[tasks.Length]; | |
for (int i = 0; i < tasks.Length; i++) | |
{ | |
faultedContinuations[i] = tasks[i].ContinueWith(_ => {}, TaskContinuationOptions.OnlyOnFaulted); | |
} | |
var faultedTask = Task.WhenAny(faultedContinuations); | |
var successTask = Task.WhenAll(tasks); | |
return Task.WhenAny(faultedTask, successTask); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment