BryanWilhite / Songhay.Feeds

Collects Syndication feeds in JSON format for UI presentation.
MIT License
0 stars 0 forks source link

HttpClient should static and or lazy #9

Closed BryanWilhite closed 5 years ago

BryanWilhite commented 5 years ago

depends on https://github.com/BryanWilhite/SonghayCore/issues/18

BryanWilhite commented 5 years ago

the subtlety here is that my intention is that all the feed downloads share the same HttpClient this means the downloads cannot run in parallel (so no Task.WhenAll / Task.WaitAll):

internal void DownloadFeeds(FeedsMetadata meta, string rootDirectory)
{
    if (string.IsNullOrEmpty(meta.FeedsDirectory))
        throw new NullReferenceException("The expected feeds directory is not configured.");

    foreach (var feed in meta.Feeds)
        this.DownloadFeedAsync(feed, rootDirectory).GetAwaiter().GetResult();
}

the explicit use of foreach with GetAwaiter().GetResult() shows the intent to run several async tasks sequentially

image

image

the above caveats suggest that i should not use GetAwaiter().GetResult() in, say, Azure Functions