Kanda Foundation 0.2.0
Loading...
Searching...
No Matches
AsyncUtils Class Reference

A collection of utilities and extensions to facilitate async programming. More...

Classes

struct  AsyncOperationAwaiter
 Custom await for a Unity AsyncOperation allowing it to be awaited in async/await context. More...
 
struct  UnityWebRequestAwaiter
 Custom await for UnityWebRequest allowing it to be awaited in async/await context. More...
 

Static Public Member Functions

static AsyncOperationAwaiter GetAwaiter (this AsyncOperation asyncOp)
 Extension method to easily get AsyncOperation awaiter in async/await context.
 
static UnityWebRequestAwaiter GetAwaiter (this UnityWebRequestAsyncOperation asyncOp)
 Extension method to easily get web request awaiter in async/await context.
 
static async Task YieldUntil (Func< bool > condition)
 Shorthand to wait for a condition to be met checking on each frame.
 
static async Task WaitUntil (Func< bool > condition, int pollingIntervalMs=100)
 Shorthand to wait for a condition to be met checking at a given polling interval.
 
static async Task< T > WithTimeout< T > (this Task< T > task, string taskName, int timeoutMs=10000)
 Shorthand to await a task with a given timeout.
 
static async Task WithTimeout (this Task task, string taskName, int timeoutMs=10000)
 
static async Task< T > WithRetry< T > (this Task< T > task, Func< T, bool > taskSuccessPredicate, string taskName, int numRetries=3, int retryIntervalMs=1000)
 
static async Task FireAndForget (this Task task, string taskName)
 Performs "fire and forget" (eg. for polling loops or other recurring work) for a task with proper exception logging to prevent errors from becoming unobservable.
 

Detailed Description

A collection of utilities and extensions to facilitate async programming.

Member Function Documentation

◆ FireAndForget()

static async Task FireAndForget ( this Task task,
string taskName )
inlinestatic

Performs "fire and forget" (eg. for polling loops or other recurring work) for a task with proper exception logging to prevent errors from becoming unobservable.

Parameters
taskThe task to fire and forget.
taskNameThe name of the task to use in logs.

◆ WaitUntil()

static async Task WaitUntil ( Func< bool > condition,
int pollingIntervalMs = 100 )
inlinestatic

Shorthand to wait for a condition to be met checking at a given polling interval.

Parameters
conditionA predicate that when true, this method should stop waiting.
pollingIntervalMsThe amount of time to wait between checking the predicate.
Returns
An awaitable task that will complete once the condition is true.

◆ WithTimeout< T >()

static async Task< T > WithTimeout< T > ( this Task< T > task,
string taskName,
int timeoutMs = 10000 )
inlinestatic

Shorthand to await a task with a given timeout.

Parameters
taskThe task to to await.
taskNameThe name of the task to use in logs.
timeoutMsThe timeout period, after which the task is dropped.
Template Parameters
TThe return type for the task.
Returns
A task with the same return type but an exception is thrown if the timeout period finishes before the task.
Exceptions
TimeoutExceptionThrown if the task times out.

◆ YieldUntil()

static async Task YieldUntil ( Func< bool > condition)
inlinestatic

Shorthand to wait for a condition to be met checking on each frame.

Parameters
conditionA predicate that when true, this method should stop waiting.
Returns
An awaitable task that will complete once the condition is true.

The documentation for this class was generated from the following file: