If I'm returning the result of a single asynchronous function e.g. in a service between application layers, is there any difference between:
public Task<byte[]> GetInsurancePolicyDocument(string itineraryReference)
{
return this.coreItineraryDocumentService.GetInsurancePolicyDocument(itineraryReference);
}
And:
public async Task<byte[]> GetInsurancePolicyDocument(string itineraryReference)
{
return await this.coreItineraryDocumentService.GetInsurancePolicyDocument(itineraryReference);
}
There are a few very subtle differences in some cases - for example, if the original Task
returns with a status of Faulted
but with an OperationCanceledException
then the async
version would return a task with a status of Canceled
... but unless you really need any of that subtlety, it would generally be better to go with your first code and avoid the (very slight) overhead of wrapping it.
See more on this question at Stackoverflow