I guess my question boils down to:
Given two async methods where one calls the other. Should I await in both of the methods, or just the first?
Here's my scenario. I'm writing an ASP NET CORE WEB API using CQRS and MediatR.
I have this async API method
[HttpGet]
public async Task<IActionResult> Get(Get.Query query)
{
var result = await _mediator.Send(query);
return Ok(result);
}
Should I also async/await in my RequestHandler
?
Like this
public class QueryHandler : IAsyncRequestHandler<Query, IEnumerable<Result>>
{
public async Task<IEnumerable<Result>> Handle(Query message)
{
return await _connection.QueryAsync<Result>("...");
}
}
Or should I simply do this
public class QueryHandler : IAsyncRequestHandler<Query, IEnumerable<Result>>
{
public Task<IEnumerable<Result>> Handle(Query message)
{
return _connection.QueryAsync<Result>("...");
}
}
The reason I'm puzzled is because the API request is already in a thread. So is wrapping it in another thread not the correct way to do it? I've seen examples of both :/