Skip to content

Commit 911de0f

Browse files
committed
added TaskCreationOptions.RunContinuationsAsynchronously for TSC
1 parent 88de4e7 commit 911de0f

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/bunit.core/Rendering/TestRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TestRenderer : Renderer, ITestRenderer
1212
private readonly List<RootComponent> rootComponents = new();
1313
private readonly ILogger<TestRenderer> logger;
1414
private readonly IRenderedComponentActivator activator;
15-
private TaskCompletionSource<Exception> unhandledExceptionTsc = new();
15+
private TaskCompletionSource<Exception> unhandledExceptionTsc = new(TaskCreationOptions.RunContinuationsAsynchronously);
1616
private Exception? capturedUnhandledException;
1717

1818
/// <inheritdoc/>
@@ -352,7 +352,7 @@ protected override void HandleException(Exception exception)
352352

353353
if (!unhandledExceptionTsc.TrySetResult(capturedUnhandledException))
354354
{
355-
unhandledExceptionTsc = new TaskCompletionSource<Exception>();
355+
unhandledExceptionTsc = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously);
356356
unhandledExceptionTsc.SetResult(capturedUnhandledException);
357357
}
358358
}
@@ -362,7 +362,7 @@ private void ResetUnhandledException()
362362
capturedUnhandledException = null;
363363

364364
if (unhandledExceptionTsc.Task.IsCompleted)
365-
unhandledExceptionTsc = new TaskCompletionSource<Exception>();
365+
unhandledExceptionTsc = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously);
366366
}
367367

368368
private void AssertNoUnhandledExceptions()

src/bunit.web/JSInterop/InvocationHandlers/JSRuntimeInvocationHandlerBase{TResult}.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class JSRuntimeInvocationHandlerBase<TResult>
3131
protected JSRuntimeInvocationHandlerBase(InvocationMatcher matcher, bool isCatchAllHandler)
3232
{
3333
invocationMatcher = matcher ?? throw new ArgumentNullException(nameof(matcher));
34-
completionSource = new TaskCompletionSource<TResult>();
34+
completionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
3535
IsCatchAllHandler = isCatchAllHandler;
3636
}
3737

@@ -41,7 +41,7 @@ protected JSRuntimeInvocationHandlerBase(InvocationMatcher matcher, bool isCatch
4141
protected void SetCanceledBase()
4242
{
4343
if (completionSource.Task.IsCompleted)
44-
completionSource = new TaskCompletionSource<TResult>();
44+
completionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
4545

4646
completionSource.SetCanceled();
4747
}
@@ -54,7 +54,7 @@ protected void SetExceptionBase<TException>(TException exception)
5454
where TException : Exception
5555
{
5656
if (completionSource.Task.IsCompleted)
57-
completionSource = new TaskCompletionSource<TResult>();
57+
completionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
5858

5959
completionSource.SetException(exception);
6060
}
@@ -66,7 +66,7 @@ protected void SetExceptionBase<TException>(TException exception)
6666
protected void SetResultBase(TResult result)
6767
{
6868
if (completionSource.Task.IsCompleted)
69-
completionSource = new TaskCompletionSource<TResult>();
69+
completionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
7070

7171
completionSource.SetResult(result);
7272
}

src/bunit.web/TestDoubles/Authorization/FakeAuthenticationStateProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public void TriggerUnauthenticationStateChanged()
7575
private void SetUnauthenticatedState()
7676
{
7777
if (authState.Task.IsCompleted)
78-
authState = new TaskCompletionSource<AuthenticationState>();
78+
authState = new TaskCompletionSource<AuthenticationState>(TaskCreationOptions.RunContinuationsAsynchronously);
7979

8080
authState.SetResult(CreateUnauthenticationState());
8181
}
8282

8383
private void SetAuthorizingState()
8484
{
8585
if (authState.Task.IsCompleted)
86-
authState = new TaskCompletionSource<AuthenticationState>();
86+
authState = new TaskCompletionSource<AuthenticationState>(TaskCreationOptions.RunContinuationsAsynchronously);
8787
}
8888

8989
private void SetAuthenticatedState(
@@ -93,7 +93,7 @@ private void SetAuthenticatedState(
9393
string? authenticationType)
9494
{
9595
if (authState.Task.IsCompleted)
96-
authState = new TaskCompletionSource<AuthenticationState>();
96+
authState = new TaskCompletionSource<AuthenticationState>(TaskCreationOptions.RunContinuationsAsynchronously);
9797

9898
authState.SetResult(CreateAuthenticationState(userName, roles, claims, authenticationType));
9999
}

0 commit comments

Comments
 (0)