diff --git a/src/Paramore.Brighter/Tasks/BrighterSynchronizationContext.cs b/src/Paramore.Brighter/Tasks/BrighterSynchronizationContext.cs index b58dac4f44..134a17cce5 100644 --- a/src/Paramore.Brighter/Tasks/BrighterSynchronizationContext.cs +++ b/src/Paramore.Brighter/Tasks/BrighterSynchronizationContext.cs @@ -145,9 +145,9 @@ public override void Post(SendOrPostCallback callback, object? state) //just execute inline // current thread already owns the context, so just execute inline to prevent deadlocks - //if (BrighterSynchronizationHelper.Current == SynchronizationHelper) - //SynchronizationHelper.ExecuteImmediately(contextCallback, state); - //else + if (BrighterSynchronizationHelper.Current == SynchronizationHelper) + SynchronizationHelper.ExecuteImmediately(contextCallback, state); + else base.Post(callback, state); } diff --git a/tests/Paramore.Brighter.Core.Tests/Tasks/BrighterSynchronizationContextsTests.cs b/tests/Paramore.Brighter.Core.Tests/Tasks/BrighterSynchronizationContextsTests.cs index 92f3108fde..c3c9f2c2f7 100644 --- a/tests/Paramore.Brighter.Core.Tests/Tasks/BrighterSynchronizationContextsTests.cs +++ b/tests/Paramore.Brighter.Core.Tests/Tasks/BrighterSynchronizationContextsTests.cs @@ -6,15 +6,13 @@ #endregion using System; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using FluentAssertions; -using Paramore.Brighter.ServiceActivator; using Paramore.Brighter.Tasks; using Xunit; -namespace Paramore.Brighter.Core.Tests.SynchronizationContext; +namespace Paramore.Brighter.Core.Tests.Tasks; public class BrighterSynchronizationContextsTests { @@ -123,6 +121,20 @@ public void Run_AsyncTaskWithResult_BlockingCode_Still_Ends() resumed.Should().BeTrue(); result.Should().Be(17); } + + [Fact] + public void Run_AsyncTaskWithResultAndConfigurateAwait_BlockingCode_Still_Ends() + { + bool resumed = false; + var result = BrighterSynchronizationHelper.Run(async () => + { + await Task.Delay(50).ConfigureAwait(false); + resumed = true; + return 17; + }); + resumed.Should().BeTrue(); + result.Should().Be(17); + } [Fact] public void Run_AsyncTaskWithResult_ContainsMultipleAsyncTasks_Still_Ends()