Skip to content

Commit 88de4e7

Browse files
committed
refactor: use async/await for dispatcher and async continuation
1 parent 9aa2a5d commit 88de4e7

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected WaitForHelper(
5151
this.completeChecker = completeChecker ?? throw new ArgumentNullException(nameof(completeChecker));
5252

5353
logger = renderedFragment.Services.CreateLogger<WaitForHelper<T>>();
54-
checkPassedCompletionSource = new TaskCompletionSource<T>();
54+
checkPassedCompletionSource = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
5555
timer = new Timer(_ =>
5656
{
5757
logger.LogWaiterTimedOut(renderedFragment.ComponentId);
@@ -121,17 +121,12 @@ private Task<T> CreateWaitTask(IRenderedFragmentBase renderedFragment)
121121

122122
// Two to failure conditions, that the renderer captures an unhandled
123123
// exception from a component or itself, or that the timeout is reached,
124-
// are executed on the renderes scheduler, to ensure that OnAfterRender
124+
// are executed on the renderers scheduler, to ensure that OnAfterRender
125125
// and the continuations does not happen at the same time.
126-
var failureTask = renderer.Dispatcher.InvokeAsync(() =>
126+
var failureTask = renderer.Dispatcher.InvokeAsync(async () =>
127127
{
128-
return renderer
129-
.UnhandledException
130-
.ContinueWith(
131-
x => Task.FromException<T>(x.Result),
132-
CancellationToken.None,
133-
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
134-
TaskScheduler.FromCurrentSynchronizationContext());
128+
var exception = await renderer.UnhandledException;
129+
return Task.FromException<T>(exception);
135130
}).Unwrap();
136131

137132
return Task

0 commit comments

Comments
 (0)