I have a bunch of async tasks that may or may not be run based on the results of other expressions. Howerever, I still want to be able to await them all, but I can't do this since some will not be initialized. How can I default initialize a Task? For example:
Task<string> ownerTask;
if(fields.Select(x => x.Name == "owner").Any())
{
ownerTask = _repo.GetOwnerIdFromIssueId(issueId);
}
await Task.WhenAll(ownerTask, anothertask, anothertask, etc);
In this example, "ownerTask" may or may not actually have a task associated with it depending on the result of the if statement, but I don't want to have to block my thread by awaiting the task inside of the if.
Thanks!