mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 11:42:54 +08:00
Add cancellation support to game-side IResourceStore
s
This commit is contained in:
parent
0732a9e6da
commit
1040590844
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Audio;
|
||||
@ -184,7 +185,8 @@ namespace osu.Game.Tests.Gameplay
|
||||
|
||||
public byte[] Get(string name) => name == resourceName ? TestResources.GetStore().Get("Resources/Samples/test-sample.mp3") : null;
|
||||
|
||||
public Task<byte[]> GetAsync(string name) => name == resourceName ? TestResources.GetStore().GetAsync("Resources/Samples/test-sample.mp3") : null;
|
||||
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
||||
=> name == resourceName ? TestResources.GetStore().GetAsync("Resources/Samples/test-sample.mp3", cancellationToken) : null;
|
||||
|
||||
public Stream GetStream(string name) => name == resourceName ? TestResources.GetStore().GetStream("Resources/Samples/test-sample.mp3") : null;
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -114,7 +115,7 @@ namespace osu.Game.Tests.Rulesets
|
||||
|
||||
public Sample Get(string name) => null;
|
||||
|
||||
public Task<Sample> GetAsync(string name) => null;
|
||||
public Task<Sample> GetAsync(string name, CancellationToken cancellationToken = default) => null;
|
||||
|
||||
public Stream GetStream(string name) => null;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.IO.Stores;
|
||||
|
||||
@ -33,7 +34,7 @@ namespace osu.Game.IO.Archives
|
||||
|
||||
public virtual byte[] Get(string name) => GetAsync(name).Result;
|
||||
|
||||
public async Task<byte[]> GetAsync(string name)
|
||||
public async Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using (Stream input = GetStream(name))
|
||||
{
|
||||
@ -41,7 +42,7 @@ namespace osu.Game.IO.Archives
|
||||
return null;
|
||||
|
||||
byte[] buffer = new byte[input.Length];
|
||||
await input.ReadAsync(buffer).ConfigureAwait(false);
|
||||
await input.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Localisation;
|
||||
|
||||
@ -75,7 +76,7 @@ namespace osu.Game.Localisation
|
||||
}
|
||||
}
|
||||
|
||||
public Task<string> GetAsync(string lookup)
|
||||
public Task<string> GetAsync(string lookup, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.FromResult(Get(lookup));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
@ -115,7 +116,7 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
public Sample Get(string name) => primary.Get(name) ?? fallback.Get(name);
|
||||
|
||||
public Task<Sample> GetAsync(string name) => primary.GetAsync(name) ?? fallback.GetAsync(name);
|
||||
public Task<Sample> GetAsync(string name, CancellationToken cancellationToken = default) => primary.GetAsync(name, cancellationToken) ?? fallback.GetAsync(name, cancellationToken);
|
||||
|
||||
public Stream GetStream(string name) => primary.GetStream(name) ?? fallback.GetStream(name);
|
||||
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
@ -166,7 +167,7 @@ namespace osu.Game.Tests.Beatmaps
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public Task<byte[]> GetAsync(string name)
|
||||
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
||||
{
|
||||
markLookup(name);
|
||||
return Task.FromResult(Array.Empty<byte>());
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
@ -352,7 +353,7 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
public Track Get(string name) => throw new NotImplementedException();
|
||||
|
||||
public Task<Track> GetAsync(string name) => throw new NotImplementedException();
|
||||
public Task<Track> GetAsync(string name, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public Stream GetStream(string name) => throw new NotImplementedException();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user