Multiple Awaits in a single method
I have a method like this:
public static async Task SaveAllAsync() {
foreach (var kvp in configurationFileMap) {
await SaveConfigurationAsync(kvp.Key);
}
}
But I'm struggling to follow what will happen when someone calls
SaveAllAsync().
When someone first calls it, I believe SaveAllAsync() will return control
to the caller the first time it hits the line await
SaveConfigurationAsync(kvp.Key);.
But then I'm unclear; without the use of threading; how can
SaveConfigurationAsync(kvp.Key) continue? Or is threading actually
involved (I've read that it isn't necessarily).
Also, when the first await SaveConfigurationAsync(kvp.Key) is completed,
does SaveAllAsync() continue on to the next line?
Or do all the calls to SaveConfigurationAsync(kvp.Key) get 'blocked up'
until the caller awaits SaveAllAsync()?
No comments:
Post a Comment