using System; using System.Reflection; using System.Threading.Tasks; using Nito.AsyncEx; namespace Abp.Threading { /// /// Provides some helper methods to work with async methods. /// public static class AsyncHelper { /// /// Checks if given method is an async method. /// /// A method to check public static bool IsAsync(this MethodInfo method) { return ( method.ReturnType == typeof(Task) || (method.ReturnType.GetTypeInfo().IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)) ); } /// /// Checks if given method is an async method. /// /// A method to check [Obsolete("Use MethodInfo.IsAsync() extension method!")] public static bool IsAsyncMethod(MethodInfo method) { return method.IsAsync(); } /// /// Runs a async method synchronously. /// /// A function that returns a result /// Result type /// Result of the async operation public static TResult RunSync(Func> func) { return AsyncContext.Run(func); } /// /// Runs a async method synchronously. /// /// An async action public static void RunSync(Func action) { AsyncContext.Run(action); } } }