Handle task exception outside of schedule to avoid unobserved exceptions

This commit is contained in:
Dean Herbert 2022-06-28 15:09:28 +09:00
parent a2701a3205
commit 22b254e5c5
1 changed files with 11 additions and 7 deletions

View File

@ -294,17 +294,21 @@ private void sendNextBundleIfRequired()
lastSend = tcs.Task;
SendFramesInternal(bundle).ContinueWith(t => Schedule(() =>
SendFramesInternal(bundle).ContinueWith(t =>
{
// Handle exception outside of `Schedule` to ensure it doesn't go unovserved.
bool wasSuccessful = t.Exception == null;
// If the last bundle send wasn't successful, try again without dequeuing.
if (wasSuccessful)
pendingFrameBundles.Dequeue();
return Schedule(() =>
{
// If the last bundle send wasn't successful, try again without dequeuing.
if (wasSuccessful)
pendingFrameBundles.Dequeue();
tcs.SetResult(wasSuccessful);
sendNextBundleIfRequired();
}));
tcs.SetResult(wasSuccessful);
sendNextBundleIfRequired();
});
});
}
}
}