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 SourceIsAsync(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 |
IsTaskOrTaskOfT(Type)
Declaration
public static bool IsTaskOrTaskOfT(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type |
Returns
Type | Description |
---|---|
System.Boolean |
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 |
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 |
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. |
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. |
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 |