I'm trying to understand the consequences of two approaches to passing a lambda into an async method that executes the lambda. The below example distills the two approaches. In the first approach, the lambda itself async whereas it isn't in the second approach.
While this is a contrived example, I'm trying to determine if either approach is more "correct", handles corner cases better (e.g. if the lambda throws), has significantly better performance, and so on. Are these approaches, from the caller's perspective, functionally equivalent?
class Program
{
static async Task Main(string[] args)
{
var result1 = await ExecuteFuncAsync(
async () =>
{
var funcResult = await Task.FromResult(false);
return funcResult;
});
var result2 = await ExecuteFuncAsync(
() =>
{
var funcResult = Task.FromResult(false);
return funcResult;
});
}
private static async Task<bool> ExecuteFuncAsync(Func<Task<bool>> func)
{
return await func();
}
}