mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 11:12:54 +08:00
Fix bundle send logic not correctly waiting for task completion (due to nested schedule)
This commit is contained in:
parent
c94e7e2abe
commit
47b84295a6
@ -221,8 +221,7 @@ namespace osu.Game.Online.Spectator
|
||||
|
||||
protected abstract Task BeginPlayingInternal(SpectatorState state);
|
||||
|
||||
protected abstract Task SendFramesInternal(FrameDataBundle data);
|
||||
|
||||
protected abstract Task SendFramesInternal(FrameDataBundle bundle);
|
||||
protected abstract Task EndPlayingInternal(SpectatorState state);
|
||||
|
||||
protected abstract Task WatchUserInternal(int userId);
|
||||
@ -281,19 +280,27 @@ namespace osu.Game.Online.Spectator
|
||||
|
||||
private void sendNextBundleIfRequired()
|
||||
{
|
||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||
|
||||
if (lastSend?.IsCompleted == false)
|
||||
return;
|
||||
|
||||
if (!pendingFrameBundles.TryPeek(out var bundle))
|
||||
return;
|
||||
|
||||
lastSend = SendFramesInternal(bundle);
|
||||
lastSend.ContinueWith(t => Schedule(() =>
|
||||
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
lastSend = tcs.Task;
|
||||
|
||||
SendFramesInternal(bundle).ContinueWith(t => Schedule(() =>
|
||||
{
|
||||
bool wasSuccessful = t.Exception == null;
|
||||
|
||||
// If the last bundle send wasn't successful, try again without dequeuing.
|
||||
if (t.IsCompletedSuccessfully)
|
||||
if (wasSuccessful)
|
||||
pendingFrameBundles.Dequeue();
|
||||
|
||||
tcs.SetResult(wasSuccessful);
|
||||
sendNextBundleIfRequired();
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user