Skip to content

Commit 7ca8f7c

Browse files
Eliminate ContinueWith from Renderer.cs. Fixes #6385
1 parent d62d33c commit 7ca8f7c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/Components/Components/src/Rendering/Renderer.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ private void ProcessRenderQueue()
455455
}
456456
finally
457457
{
458-
RemoveEventHandlerIds(_batchBuilder.DisposedEventHandlerIds.ToRange(), updateDisplayTask);
458+
// RemoveEventHandlerIdsAsync is designed to be fired-and-forgotten
459+
// It will clone and persist any state it needs if it needs to run asynchronously
460+
_ = RemoveEventHandlerIdsAsync(_batchBuilder.DisposedEventHandlerIds.ToRange(), updateDisplayTask);
461+
459462
_batchBuilder.ClearStateForCurrentBatch();
460463
_isBatchInProgress = false;
461464
}
@@ -599,14 +602,14 @@ private void RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
599602
}
600603
}
601604

602-
private void RemoveEventHandlerIds(ArrayRange<int> eventHandlerIds, Task afterTask)
605+
private async Task RemoveEventHandlerIdsAsync(ArrayRange<int> eventHandlerIds, Task afterTaskIgnoreErrors)
603606
{
604607
if (eventHandlerIds.Count == 0)
605608
{
606609
return;
607610
}
608611

609-
if (afterTask.IsCompleted)
612+
if (afterTaskIgnoreErrors.IsCompleted)
610613
{
611614
var array = eventHandlerIds.Array;
612615
var count = eventHandlerIds.Count;
@@ -622,8 +625,19 @@ private void RemoveEventHandlerIds(ArrayRange<int> eventHandlerIds, Task afterTa
622625
// any further). We must clone the data because the underlying RenderBatchBuilder
623626
// may be reused and hence modified by an unrelated subsequent batch.
624627
var eventHandlerIdsClone = eventHandlerIds.Clone();
625-
afterTask.ContinueWith(_ =>
626-
RemoveEventHandlerIds(eventHandlerIdsClone, Task.CompletedTask));
628+
629+
try
630+
{
631+
await afterTaskIgnoreErrors;
632+
}
633+
catch (Exception)
634+
{
635+
// As per method contract, we're not error-handling the task.
636+
// That remains the caller's business.
637+
}
638+
639+
// We know the next execution will complete synchronously, so nothing to await
640+
_ = RemoveEventHandlerIdsAsync(eventHandlerIdsClone, Task.CompletedTask);
627641
}
628642
}
629643

0 commit comments

Comments
 (0)