Qual é o objetivo de "retornar aguardar" em c #?
Existequalquer cenário onde escrever método como este:
public async Task<SomeResult> DoSomethingAsync()
{
// Some synchronous code might or might not be here... //
return await DoAnotherThingAsync();
}
em vez disso:
public Task<SomeResult> DoSomethingAsync()
{
// Some synchronous code might or might not be here... //
return DoAnotherThingAsync();
}
faria sentido?
Por que usarreturn await
construir quando você pode retornar diretamenteTask<T>
do interiorDoAnotherThingAsync()
invocação?
Vejo código comreturn await
em muitos lugares, acho que posso ter perdido alguma coisa. Mas, até onde eu entendo, não usar palavras-chave async / await neste caso e retornar diretamente a tarefa seria funcionalmente equivalente. Por que adicionar sobrecarga adicional deawait
camada?