Yes, that is a perfectly reasonable way of going about it. Why do you feel that you may be abusing the pattern?
Think of it this way:
- a synchronous method returning
void
corresponds to an async method returningTask
. Likewise, - a synchronous method returning
T
corresponds to an async method returningTask<T>
.
That is why you cannot do
protected override async Task OnReceived(IRequest request, string connectionId, string data)
{
return Connection.Broadcast(data);
}
, since the async
keyword and your return statement would indicate a method that returned Task<Task>
.
What you can do is remove your last await
altogether. All it will do is create an empty continuation (because it is essentially saying "when the broadcast is done, run the code after the broadcast and until the ending curly brace"). Or you can leave it in for consistency, if you prefer.