From 8d1dffc7434636811f4877e45143bd39309d087f Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Sat, 19 Jun 2021 20:44:29 +0000 Subject: [PATCH] Make cfgProviders asynchronous (in a quite bad ways sometimes...) --- QuickPlay/Configuration.cs | 12 ++++++------ QuickPlay/QuickPlay.csproj | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/QuickPlay/Configuration.cs b/QuickPlay/Configuration.cs index 3ab5a5d..9c45760 100644 --- a/QuickPlay/Configuration.cs +++ b/QuickPlay/Configuration.cs @@ -77,7 +77,7 @@ namespace QuickPlay { // TODO: decide sensibly var cfgProvider = new HttpConfigurationProvider(playerConfigUrl); - return cfgProvider.GetConfiguration(); + return cfgProvider.GetConfigurationAsync().Result; // Bad code, but hopefully we dont hang. } // We want to compare by values. @@ -131,7 +131,7 @@ namespace QuickPlay interface IPlayerConfigurationProvider { - PlayerConfiguration GetConfiguration(); + Task GetConfigurationAsync(); } sealed class HttpConfigurationProvider : IPlayerConfigurationProvider @@ -141,7 +141,7 @@ namespace QuickPlay { configUrl = url; } - public async Task GetConfiguration() + public async Task GetConfigurationAsync() { var client = new HttpClient() ; var resp = await client.GetStreamAsync(configUrl); @@ -162,15 +162,15 @@ namespace QuickPlay { this.reader = new StreamReader(filename); } - public PlayerConfiguration GetConfiguration() + public Task GetConfigurationAsync() { - return PlayerConfiguration.FromFile(reader); + return Task.FromResult(PlayerConfiguration.FromFile(reader)); } } sealed class DummyConfigurationProvider : IPlayerConfigurationProvider { - public PlayerConfiguration GetConfiguration() => null; + public Task GetConfigurationAsync() => null; } class Song: IPlayable diff --git a/QuickPlay/QuickPlay.csproj b/QuickPlay/QuickPlay.csproj index 2d3d180..ff49baa 100644 --- a/QuickPlay/QuickPlay.csproj +++ b/QuickPlay/QuickPlay.csproj @@ -60,6 +60,7 @@ + @@ -68,6 +69,7 @@ +