You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
I noticed that IConnection has three events that return a Task: Connected, Received and Closed.
Oddly, Connected and Closed don't use that returned value.
And for Received, the task is added to a TaskQueue.
However, event delegates are multicast (many "subscribers"), so only the Task of the last subscriber is used.
As such, it is not typically recommended for events to have return types. But, in the case, a possible solution could be to explicitly invoke & await each subscriber, like this:
if (receivedHandler != null)
{
foreach (var d in receivedHandler.GetInvocationList().OfType<Func<byte[], Task>>())
{
await d(buffer);
}
}
I noticed that
IConnectionhas three events that return aTask:Connected,ReceivedandClosed.Oddly,
ConnectedandCloseddon't use that returned value.And for
Received, the task is added to aTaskQueue.However, event delegates are multicast (many "subscribers"), so only the
Taskof the last subscriber is used.As such, it is not typically recommended for events to have return types. But, in the case, a possible solution could be to explicitly invoke & await each subscriber, like this:
Based on this answer on StackOverflow.