mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Refactor cancellation logic
This commit is contained in:
parent
4c0d76573c
commit
dfa076c169
@ -319,9 +319,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
countdownStopSource?.Cancel();
|
countdownStopSource?.Cancel();
|
||||||
|
|
||||||
|
// Note that this will leak CTSs, however this is a test method and we haven't noticed foregoing disposal of non-linked CTSs to be detrimental.
|
||||||
|
// If necessary, this can be moved into the final schedule below, and the class-level fields be nulled out accordingly.
|
||||||
var stopSource = countdownStopSource = new CancellationTokenSource();
|
var stopSource = countdownStopSource = new CancellationTokenSource();
|
||||||
var skipSource = countdownSkipSource = new CancellationTokenSource();
|
var skipSource = countdownSkipSource = new CancellationTokenSource();
|
||||||
var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(stopSource.Token, skipSource.Token);
|
|
||||||
var countdown = new MatchStartCountdown { TimeRemaining = matchCountdownRequest.Duration };
|
var countdown = new MatchStartCountdown { TimeRemaining = matchCountdownRequest.Duration };
|
||||||
|
|
||||||
Task lastCountdownTask = countdownTask;
|
Task lastCountdownTask = countdownTask;
|
||||||
@ -342,7 +343,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Delay(matchCountdownRequest.Duration, cancellationSource.Token).ConfigureAwait(false);
|
using (var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(stopSource.Token, skipSource.Token))
|
||||||
|
await Task.Delay(matchCountdownRequest.Duration, cancellationSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
@ -351,19 +353,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
using (cancellationSource)
|
if (Room.Countdown != countdown)
|
||||||
{
|
return;
|
||||||
if (Room.Countdown != countdown)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Room.Countdown = null;
|
Room.Countdown = null;
|
||||||
MatchEvent(new CountdownChangedEvent { Countdown = null });
|
MatchEvent(new CountdownChangedEvent { Countdown = null });
|
||||||
|
|
||||||
if (stopSource.Token.IsCancellationRequested)
|
if (stopSource.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
StartMatch().WaitSafely();
|
StartMatch().WaitSafely();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user