1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

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.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Platform;
using osu.Game;
using osu.Game.Configuration;
using osu.Game.Graphics;
@ -24,15 +23,13 @@ namespace osu.Desktop.Overlays
private OsuConfigManager config;
private OsuGameBase game;
private NotificationOverlay notificationOverlay;
private GameHost host;
[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;
this.config = config;
this.game = game;
this.host = host;
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre;

View File

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