Firstly, your example doesn't make sense, you're either returning something, or not, returning the results of the awaited function without a return type would be a compiler error.
public async Task MethodOneAsync()
{
return await DoSomethingAsync(() => SomeActionAsync());
}
Secondly, this has nothing to do with "true" async as that would be an implementation detail which is not shown
Thirdly, the only difference between either of the hypothetical examples
await DoSomethingAsync(async () => await SomeActionAsync());
and
await DoSomethingAsync(() => SomeActionAsync());
Given the definition of DoSomethingAsync
, in the first example the compiler will create an extra IAsyncStateMachine
implementation, instead of just forwarding the Task
. I.e More compiled code, more IL, more instructions, and in this example seemingly redundant.
There are is a small caveat with exceptions when eliding tasks, however because this is just a simple pass through there is no other code which will throw, ergo the extra state-machine or try catch and Task.FromException
is not needed.
The real appreciable differences would come if your signature was actually an Action
instead of Func<Task>
which would create an async void
given an async lambda, however this is not case in your question.