Asynchronized events
This PR changes signatures of all events from void(object, EventArgs)
to Task(EventArgs)
or Task()
. This prevents event lambdas from being async void
, which is a bad practice, and makes them proper async Task
instead.
This gives the advantage of not crashing the CLR in the event of an exception occurring within an event handler, instead it propagates them to the caller, and makes all event handlers awaitable.
In addition to that, sender
argument was removed from the event handler delegate, since it did not appear to be used.
This means that event registration has changed like so:
Old method | New method | |
---|---|---|
Non-async | client.Event += (o, e) => { /* code here... */ }; |
client.Event += e => { /* code here... */ return Task.Delay(0); }; |
Async | client.Event += async (o, e) => { /* code here... */ }; |
client.Event += async e => { /* code here... */ } |
Should this get merged, the wiki and documentation should be updated to reflect these changes. I will also update the example bot.