Reduce async-await pairs

This commit is contained in:
Dean Herbert 2018-08-29 20:57:48 +09:00
parent 73c764d983
commit b1a3dfedd1
4 changed files with 12 additions and 12 deletions

View File

@ -319,17 +319,17 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.
/// </summary> /// </summary>
public async Task ImportFromStable() public Task ImportFromStable()
{ {
var stable = GetStableStorage?.Invoke(); var stable = GetStableStorage?.Invoke();
if (stable == null) if (stable == null)
{ {
Logger.Log("No osu!stable installation available!", LoggingTarget.Information, LogLevel.Error); Logger.Log("No osu!stable installation available!", LoggingTarget.Information, LogLevel.Error);
return; return Task.CompletedTask;
} }
await Task.Factory.StartNew(() => Import(stable.GetDirectories("Songs").Select(f => stable.GetFullPath(f)).ToArray()), TaskCreationOptions.LongRunning); return Task.Factory.StartNew(() => Import(stable.GetDirectories("Songs").Select(f => stable.GetFullPath(f)).ToArray()), TaskCreationOptions.LongRunning);
} }
/// <summary> /// <summary>

View File

@ -67,7 +67,7 @@ namespace osu.Game.Beatmaps
public bool BeatmapLoaded => beatmap.IsResultAvailable; public bool BeatmapLoaded => beatmap.IsResultAvailable;
public IBeatmap Beatmap => beatmap.Value.Result; public IBeatmap Beatmap => beatmap.Value.Result;
public async Task<IBeatmap> GetBeatmapAsync() => await beatmap.Value; public Task<IBeatmap> GetBeatmapAsync() => beatmap.Value;
private readonly AsyncLazy<IBeatmap> beatmap; private readonly AsyncLazy<IBeatmap> beatmap;
private IBeatmap populateBeatmap() private IBeatmap populateBeatmap()
@ -138,14 +138,14 @@ namespace osu.Game.Beatmaps
public bool BackgroundLoaded => background.IsResultAvailable; public bool BackgroundLoaded => background.IsResultAvailable;
public Texture Background => background.Value.Result; public Texture Background => background.Value.Result;
public async Task<Texture> GetBackgroundAsync() => await background.Value; public Task<Texture> GetBackgroundAsync() => background.Value;
private AsyncLazy<Texture> background; private AsyncLazy<Texture> background;
private Texture populateBackground() => GetBackground(); private Texture populateBackground() => GetBackground();
public bool TrackLoaded => track.IsResultAvailable; public bool TrackLoaded => track.IsResultAvailable;
public Track Track => track.Value.Result; public Track Track => track.Value.Result;
public async Task<Track> GetTrackAsync() => await track.Value; public Task<Track> GetTrackAsync() => track.Value;
private AsyncLazy<Track> track; private AsyncLazy<Track> track;
private Track populateTrack() private Track populateTrack()
@ -158,21 +158,21 @@ namespace osu.Game.Beatmaps
public bool WaveformLoaded => waveform.IsResultAvailable; public bool WaveformLoaded => waveform.IsResultAvailable;
public Waveform Waveform => waveform.Value.Result; public Waveform Waveform => waveform.Value.Result;
public async Task<Waveform> GetWaveformAsync() => await waveform.Value; public Task<Waveform> GetWaveformAsync() => waveform.Value;
private readonly AsyncLazy<Waveform> waveform; private readonly AsyncLazy<Waveform> waveform;
private Waveform populateWaveform() => GetWaveform(); private Waveform populateWaveform() => GetWaveform();
public bool StoryboardLoaded => storyboard.IsResultAvailable; public bool StoryboardLoaded => storyboard.IsResultAvailable;
public Storyboard Storyboard => storyboard.Value.Result; public Storyboard Storyboard => storyboard.Value.Result;
public async Task<Storyboard> GetStoryboardAsync() => await storyboard.Value; public Task<Storyboard> GetStoryboardAsync() => storyboard.Value;
private readonly AsyncLazy<Storyboard> storyboard; private readonly AsyncLazy<Storyboard> storyboard;
private Storyboard populateStoryboard() => GetStoryboard(); private Storyboard populateStoryboard() => GetStoryboard();
public bool SkinLoaded => skin.IsResultAvailable; public bool SkinLoaded => skin.IsResultAvailable;
public Skin Skin => skin.Value.Result; public Skin Skin => skin.Value.Result;
public async Task<Skin> GetSkinAsync() => await skin.Value; public Task<Skin> GetSkinAsync() => skin.Value;
private readonly AsyncLazy<Skin> skin; private readonly AsyncLazy<Skin> skin;
private Skin populateSkin() => GetSkin(); private Skin populateSkin() => GetSkin();

View File

@ -71,7 +71,7 @@ namespace osu.Game.Graphics
private volatile int screenShotTasks; private volatile int screenShotTasks;
public async Task TakeScreenshotAsync() => await Task.Run(async () => public Task TakeScreenshotAsync() => Task.Run(async () =>
{ {
Interlocked.Increment(ref screenShotTasks); Interlocked.Increment(ref screenShotTasks);

View File

@ -111,10 +111,10 @@ namespace osu.Game.Skinning
byte[] IResourceStore<byte[]>.Get(string name) => GetAsync(name).Result; byte[] IResourceStore<byte[]>.Get(string name) => GetAsync(name).Result;
public async Task<byte[]> GetAsync(string name) public Task<byte[]> GetAsync(string name)
{ {
string path = getPathForFile(name); string path = getPathForFile(name);
return path == null ? null : await underlyingStore.GetAsync(path); return path == null ? Task.FromResult<byte[]>(null) : underlyingStore.GetAsync(path);
} }
#region IDisposable Support #region IDisposable Support