-
Notifications
You must be signed in to change notification settings - Fork 2
/
BaseLine_WithoutThrottling.cs
33 lines (29 loc) · 1.24 KB
/
BaseLine_WithoutThrottling.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using ThrottledParallelism.Helpers; //GetAwaiter for IEnumerable<Task>
namespace ThrottledParallelism.Strategies
{
public class BaseLine_WithoutThrottling : IGovernedParallelDownloader
{
static readonly HttpClient client = new HttpClient();
public async Task DownloadThemAllAsync(IEnumerable<Uri> uris, ProcessResult processResult, byte maxThreads)
{
Task workerTask(Uri uri) => WorkerAsync(uri, processResult); //!SPOT: Partial function
await uris.Select(workerTask); //!SPOT: Customer awaiter
}
//public Task DownloadThemAllAsync(IEnumerable<Uri> uris, ProcessResult processResult, byte maxThreads)
//{
// Task workerTask(Uri uri) => WorkerAsync(uri, processResult); //!SPOT: Partial function
// return Task.WhenAll(uris.Select(workerTask));
//}
async Task WorkerAsync(Uri uri, ProcessResult processResult)
{
var content = await client.GetStringAsync(uri).ConfigureAwait(false);
processResult(Thread.CurrentThread.ManagedThreadId.ToString(), content);
}
}
}