In the code below, is there a difference between the calls in WithoutInnerAwait
and WithInnerAwait
?
Or in other words:
When using a lambda to wrap an async function, do I need to mark the lambda as async and use await inside? Or is it enough to simply await the lambda when it's called?
private async Task DoStuff(Func<Task> lambda)
{
await lambda();
}
public async Task WithoutInnerAwait()
{
await DoStuff(() => Task.Delay(5000));
}
public async Task WithInnerAwait()
{
await DoStuff(async () => await Task.Delay(5000));
}