OpenMod Docs OpenMod Docs
OpenMod Docs OpenMod Docs
OpenMod .NET Plugin Framework.

Class AsyncHelper

Inheritance
System.Object
AsyncHelper
Namespace: OpenMod.Core.Helpers
Assembly: OpenMod.Core.dll
Syntax
public static class AsyncHelper : object

Methods

| Improve this Doc View Source

IsAsync(MethodInfo)

Checks if given method is an async method.

Declaration
public static bool IsAsync(this MethodInfo method)
Parameters
Type Name Description
MethodInfo method

A method to check

Returns
Type Description
System.Boolean
| Improve this Doc View Source

IsTaskOrTaskOfT(Type)

Declaration
public static bool IsTaskOrTaskOfT(this Type type)
Parameters
Type Name Description
Type type
Returns
Type Description
System.Boolean
| Improve this Doc View Source

RunSync(Func<Task>)

Runs a async method synchronously.

Declaration
public static void RunSync(Func<Task> action)
Parameters
Type Name Description
Func<Task> action

An async action

| Improve this Doc View Source

RunSync<TResult>(Func<Task<TResult>>)

Runs a async method synchronously.

Declaration
public static TResult RunSync<TResult>(Func<Task<TResult>> func)
Parameters
Type Name Description
Func<Task<TResult>> func

A function that returns a result

Returns
Type Description
TResult

Result of the async operation

Type Parameters
Name Description
TResult

Result type

| Improve this Doc View Source

Schedule(String, Func<Task>, Nullable<Action<Exception>>)

Schedules a task on a different thread (fire and forget)

Declaration
public static void Schedule(string name, Func<Task> task, Action<Exception>? exceptionHandler = null)
Parameters
Type Name Description
System.String name

The name of the task.

Func<Task> task

The task to run.

System.Nullable<Action<Exception>> exceptionHandler

The optional exception handler.

| Improve this Doc View Source

Schedule(String, Func<Task>, Nullable<CancellationToken>, Nullable<Action<Exception>>)

Schedules a task on a different thread (fire and forget)

Declaration
public static void Schedule(string name, Func<Task> task, CancellationToken? cancellationToken, Action<Exception>? exceptionHandler = null)
Parameters
Type Name Description
System.String name

The name of the task.

Func<Task> task

The task to run.

System.Nullable<CancellationToken> cancellationToken

The optional cancellation token.

System.Nullable<Action<Exception>> exceptionHandler

The optional exception handler.

| Improve this Doc View Source

UnwrapTask(Type)

Returns void if given type is Task. Return T, if given type is Task{T}. Returns given type otherwise.

Declaration
public static Type UnwrapTask(Type type)
Parameters
Type Name Description
Type type
Returns
Type Description
Type