Skip to content

Commit 600c6a3

Browse files
Fix missing using in polyfill (#16)
1 parent e92f436 commit 600c6a3

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/Task/Polyfills/ListExtensions.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,23 @@ public static async Task ForEachAsync<TSource>(
5151
if (body == null) throw new ArgumentNullException(nameof(body));
5252
if (degreeOfParallelism < 1) throw new ArgumentOutOfRangeException(nameof(degreeOfParallelism), "Degree of parallelism must be at least 1.");
5353

54-
var semaphore = new SemaphoreSlim(degreeOfParallelism);
55-
56-
var tasks = source.Select(async item =>
54+
using (var semaphore = new SemaphoreSlim(degreeOfParallelism))
5755
{
58-
await semaphore.WaitAsync();
59-
try
60-
{
61-
await body(item);
62-
}
63-
finally
56+
var tasks = source.Select(async item =>
6457
{
65-
semaphore.Release();
66-
}
67-
});
58+
await semaphore.WaitAsync().ConfigureAwait(false);
59+
try
60+
{
61+
await body(item).ConfigureAwait(false);
62+
}
63+
finally
64+
{
65+
semaphore.Release();
66+
}
67+
});
6868

69-
await Task.WhenAll(tasks);
69+
await Task.WhenAll(tasks).ConfigureAwait(false);
70+
}
7071
}
7172
}
7273
}

0 commit comments

Comments
 (0)