Skip to content

Commit

Permalink
Merge pull request #47 from lezzi/master
Browse files Browse the repository at this point in the history
Async code optimizations.
  • Loading branch information
poma authored Oct 15, 2016
2 parents af9bec6 + c70785b commit 6e42379
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions StatsFetcher/ProfileFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,26 @@ namespace StatsFetcher
{
public class ProfileFetcher
{
private Game game;
private HttpClient web;
private readonly Game game;
private readonly HttpClient web = new HttpClient();

public ProfileFetcher(Game game)
{
this.game = game;
this.web = new HttpClient();
}

public async Task FetchBasicProfiles()
{
var tasks = new List<Task>();

// start all requests in parallel
foreach (var p in game.Players) {
tasks.Add(FetchBasicProfile(p));
}

foreach (var task in tasks) {
await task;
}
await Task.WhenAll(game.Players.Select(FetchBasicProfile)).ConfigureAwait(false);
}

public async Task FetchFullProfiles()
{
var tasks = new List<Task>();

// start all requests in parallel
foreach (var p in game.Players) {
tasks.Add(FetchFullProfile(p));
}

foreach (var task in tasks) {
await task;
}
await Task.WhenAll(game.Players.Select(FetchFullProfile)).ConfigureAwait(false);
}

private async Task FetchBasicProfile(PlayerProfile p)
Expand Down

0 comments on commit 6e42379

Please sign in to comment.