I am trying to follow the guidance in this blog about not using await when not needed. And first off, if using { ... }
is involved, then yes - use await.
Ok, so for the following code, why does DoItTask()
not work? Is returning a Task and not using await only work if there are no uses of await in the method?
private static async Task<string> ReadOne()
{
return await readerOne.ReadAsync();
}
private static async Task<string> ReadTwo()
{
return await readerTwo.ReadAsync();
}
private static async Task<string> ReadThree()
{
return await readerOne.ReadAsync();
}
private static async Task<string> ReadCombinedAsync(string one, string two, string three)
{
return await reader.CombineAsync(one, two, three);
}
private static Task<string> ReadCombinedTask(string one, string two, string three)
{
return reader.CombineAsync(one, two, three);
}
private static async Task<string> DoItAwait()
{
string one = await ReadOne();
string two = await ReadOne();
string three = await ReadOne();
return await ReadCombinedAsync(one, two, three);
}
private static Task<string> DoItTask()
{
string one = await ReadOne();
string two = await ReadOne();
string three = await ReadOne();
return ReadCombinedAsync(one, two, three);
}
ps - I initially asked this question with a very sloppy example. Apologies for that.