mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 15:23:14 +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 BeginPlayingInternal(SpectatorState state);
|
||||||
|
|
||||||
protected abstract Task SendFramesInternal(FrameDataBundle data);
|
protected abstract Task SendFramesInternal(FrameDataBundle bundle);
|
||||||
|
|
||||||
protected abstract Task EndPlayingInternal(SpectatorState state);
|
protected abstract Task EndPlayingInternal(SpectatorState state);
|
||||||
|
|
||||||
protected abstract Task WatchUserInternal(int userId);
|
protected abstract Task WatchUserInternal(int userId);
|
||||||
@ -281,19 +280,27 @@ namespace osu.Game.Online.Spectator
|
|||||||
|
|
||||||
private void sendNextBundleIfRequired()
|
private void sendNextBundleIfRequired()
|
||||||
{
|
{
|
||||||
|
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||||
|
|
||||||
if (lastSend?.IsCompleted == false)
|
if (lastSend?.IsCompleted == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!pendingFrameBundles.TryPeek(out var bundle))
|
if (!pendingFrameBundles.TryPeek(out var bundle))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lastSend = SendFramesInternal(bundle);
|
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
|
||||||
lastSend.ContinueWith(t => Schedule(() =>
|
|
||||||
|
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 the last bundle send wasn't successful, try again without dequeuing.
|
||||||
if (t.IsCompletedSuccessfully)
|
if (wasSuccessful)
|
||||||
pendingFrameBundles.Dequeue();
|
pendingFrameBundles.Dequeue();
|
||||||
|
|
||||||
|
tcs.SetResult(wasSuccessful);
|
||||||
sendNextBundleIfRequired();
|
sendNextBundleIfRequired();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user