Skip to content

Instantly share code, notes, and snippets.

@KyleMit
Last active August 27, 2024 19:33
Show Gist options
  • Save KyleMit/ad2ce77f32d38eb0079a2bdb030191f4 to your computer and use it in GitHub Desktop.
Save KyleMit/ad2ce77f32d38eb0079a2bdb030191f4 to your computer and use it in GitHub Desktop.
await Task.WhenAll multiple conditional methods
// Update in Method
public static async Task<Person> GetPersonAsync()
{
var model = new Person();
await Task.WhenAll(
UpdateFirstName(model),
UpdateLastName(model),
UpdateAge(model)
);
return model;
}
public static async Task UpdateFirstName(Person model) {
if (!model.ShowFirstName) { return; }
model.FirstName = await GetFirstNameAsync();
}
public static async Task UpdateLastName(Person model) {
if (!model.ShowLastName) { return; }
model.LastName = await GetLastNameAsync();
}
public static async Task UpdateAge(Person model) {
if (!model.ShowAge) { return; }
model.Age = await GetAgeAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment