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
However, I find that sometimes I want to perform I/O operations or more intense processing after receiving a message. It's natural to put this sort of work in an async method, but that makes the messaging implementation a little clunky. You either have to use Task.Run() to "fire and forget" the async operation, or use async void:
// This feels clunky because you don't really have any error handling options...publicvoidReceive(MessageTypemessage){_=Task.Run(()=>ProcessMessageAsync(message));}// ... And this feels clunky because it uses async voidpublicasyncvoidReceive(MessageTypemessage){awaitProcessMessageAsync(message);}
Proposal
I propose the addition of a new interface: IAsyncRecipient<T>, and a new method on the WeakReferenceMessenger class; SendAsync().
Similar to the IRecipient interface, the IAsyncRecipient interface would define a single method:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Background
I think it would be great if we could add async versions of the standard messaging methods and interfaces.
Right now, messaging looks something like this:
However, I find that sometimes I want to perform I/O operations or more intense processing after receiving a message. It's natural to put this sort of work in an async method, but that makes the messaging implementation a little clunky. You either have to use
Task.Run()to "fire and forget" the async operation, or useasync void:Proposal
I propose the addition of a new interface:
IAsyncRecipient<T>, and a new method on theWeakReferenceMessengerclass;SendAsync().Similar to the
IRecipientinterface, theIAsyncRecipientinterface would define a single method:Then, the above clunky code could be modified to be more natural:
In addition, it may be useful to consider other "nice to have" features related to async programming, like incorporating
CancellationTokens.All reactions