ZavaruKitsu f9d25dfb83 fix!: prevent exceptions from being muted
happens by not awaiting tasks
2022-10-08 20:00:21 +03:00

28 lines
905 B
C#

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