Skip to main content

Class AsyncUtils

A set of utilities around and for better asynchronous behavior.

Assembly: Dalamud.dll
View Source
Declaration
public static class AsyncUtils

Methods

FirstSuccessfulTask<T>(ICollection<Task<T>>)

Race a set of tasks, returning either the first to succeed or an aggregate of all exceptions. This helper does not perform any automatic cancellation of losing tasks, nor does it handle exceptions of losing tasks.

View Source
Declaration
public static Task<T> FirstSuccessfulTask<T>(ICollection<Task<T>> tasks)
Returns

System.Threading.Tasks.Task<<T>>: Returns the first task that completes, according to System.Threading.Tasks.Task.IsCompletedSuccessfully.

Parameters
TypeNameDescription
System.Collections.Generic.ICollection<System.Threading.Tasks.Task<<T>>>tasksA list of tasks to race.
Type Parameters
NameDescription
TThe return type of all raced tasks.
Exceptions

System.AggregateException
Thrown when all tasks given to this method fail.

CancellableDelay(int, CancellationToken)

Provide a System.Threading.Tasks.Task.Delay(System.Int32%2cSystem.Threading.CancellationToken) that won't throw an exception when it's canceled.

View Source
Declaration
public static Task CancellableDelay(int millisecondsDelay, CancellationToken cancellationToken)
Returns

System.Threading.Tasks.Task: A task that represents the time delay.

Parameters
TypeNameDescription
System.Int32millisecondsDelayThe number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
System.Threading.CancellationTokencancellationTokenA cancellation token to observe while waiting for the task to complete.
Exceptions

System.ArgumentOutOfRangeException
The <code class="paramref">millisecondsDelay</code> argument is less than -1. System.Threading.Tasks.TaskCanceledException
The task has been canceled. System.ObjectDisposedException
The provided <code class="paramref">cancellationToken</code> has already been disposed.