|
6 | 6 | using System.Collections.Generic; |
7 | 7 | using System.Globalization; |
8 | 8 | using System.IO; |
| 9 | +using System.Linq; |
9 | 10 | using System.Threading; |
10 | 11 | using System.Threading.Tasks; |
11 | 12 | using Azure.Core; |
@@ -144,6 +145,7 @@ public async Task<Response> DownloadToInternal( |
144 | 145 | // tracing |
145 | 146 | DiagnosticScope scope = _client.ClientConfiguration.ClientDiagnostics.CreateScope(_operationName); |
146 | 147 | using DisposableBucket disposables = new DisposableBucket(); |
| 148 | + Queue<Task<Response<BlobDownloadStreamingResult>>> runningTasks = null; |
147 | 149 | try |
148 | 150 | { |
149 | 151 | scope.Start(); |
@@ -230,7 +232,6 @@ await HandleOneShotDownload(initialResponse, destination, async, cancellationTok |
230 | 232 | #pragma warning disable AZC0110 // DO NOT use await keyword in possibly synchronous scope. |
231 | 233 | // Rule checker cannot understand this section, but this |
232 | 234 | // massively reduces code duplication. |
233 | | - Queue<Task<Response<BlobDownloadStreamingResult>>> runningTasks = null; |
234 | 235 | int effectiveWorkerCount = async ? _maxWorkerCount : 1; |
235 | 236 | if (effectiveWorkerCount > 1) |
236 | 237 | { |
@@ -354,6 +355,17 @@ await CopyToInternal( |
354 | 355 | } |
355 | 356 | finally |
356 | 357 | { |
| 358 | +#pragma warning disable AZC0110 |
| 359 | + if (runningTasks != null) |
| 360 | + { |
| 361 | + async Task DisposeStreamAsync(Task<Response<BlobDownloadStreamingResult>> task) |
| 362 | + { |
| 363 | + Response<BlobDownloadStreamingResult> response = await task.ConfigureAwait(false); |
| 364 | + response.Value.Content.Dispose(); |
| 365 | + } |
| 366 | + await Task.WhenAll(runningTasks.Select(DisposeStreamAsync)).ConfigureAwait(false); |
| 367 | + } |
| 368 | +#pragma warning restore AZC0110 |
357 | 369 | scope.Dispose(); |
358 | 370 | } |
359 | 371 | } |
|
0 commit comments