We know the async
equivalent of Action
is Func<Task>
.
Therefore we could write:
Func<Task> func = async () =>
{
Console.WriteLine(@"waiting ...");
await Task.Delay(300).ConfigureAwait(false);
Console.WriteLine(@"... finished");
};
But it is also possible to write it as an Action
:
Action action = async () =>
{
Console.WriteLine(@"waiting ...");
await Task.Delay(300).ConfigureAwait(false);
Console.WriteLine(@"... finished");
};
This is syntactically correct.
How is it possible to convert Action action
into Func<Task> func
?