Use TaskCompletionSource in a better manner

This commit is contained in:
Dean Herbert 2019-05-23 19:08:44 +09:00
parent acaf2f9fbb
commit e034b3d514
2 changed files with 6 additions and 11 deletions

View File

@ -6,7 +6,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Platform;
using osu.Game; using osu.Game;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -24,15 +23,13 @@ namespace osu.Desktop.Overlays
private OsuConfigManager config; private OsuConfigManager config;
private OsuGameBase game; private OsuGameBase game;
private NotificationOverlay notificationOverlay; private NotificationOverlay notificationOverlay;
private GameHost host;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(NotificationOverlay notification, OsuColour colours, TextureStore textures, OsuGameBase game, OsuConfigManager config, GameHost host) private void load(NotificationOverlay notification, OsuColour colours, TextureStore textures, OsuGameBase game, OsuConfigManager config)
{ {
notificationOverlay = notification; notificationOverlay = notification;
this.config = config; this.config = config;
this.game = game; this.game = game;
this.host = host;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre; Anchor = Anchor.BottomCentre;

View File

@ -168,12 +168,10 @@ namespace osu.Game.Overlays
if (initialFetchTask != null) if (initialFetchTask != null)
return initialFetchTask; return initialFetchTask;
return initialFetchTask = Task.Run(async () =>
{
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
initialFetchTask = tcs.Task;
Task.Run(() =>
{
var req = new GetChangelogRequest(); var req = new GetChangelogRequest();
req.Success += res => req.Success += res =>
{ {
@ -190,9 +188,9 @@ namespace osu.Game.Overlays
}; };
req.Failure += _ => initialFetchTask = null; req.Failure += _ => initialFetchTask = null;
req.Perform(API); req.Perform(API);
});
return initialFetchTask; await tcs.Task;
});
} }
private CancellationTokenSource loadContentTask; private CancellationTokenSource loadContentTask;