using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace TelegramBotBase.Base; public static class Async { public delegate Task AsyncEventHandler(object sender, TEventArgs e) where TEventArgs : EventArgs; public static IEnumerable> GetHandlers( this AsyncEventHandler handler) where TEventArgs : EventArgs { return handler.GetInvocationList().Cast>(); } public static Task InvokeAllAsync(this AsyncEventHandler handler, object sender, TEventArgs e) where TEventArgs : EventArgs { return Task.WhenAll( handler.GetHandlers() .Select(handleAsync => handleAsync(sender, e))); } }