From 8330d4cc54b21ad4a98f40c776834ddf1060924d Mon Sep 17 00:00:00 2001 From: Ian Cooper Date: Tue, 31 Dec 2024 17:17:05 +0000 Subject: [PATCH 1/2] fix: add immediate execution back --- .../Tasks/BrighterSynchronizationContext.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Paramore.Brighter/Tasks/BrighterSynchronizationContext.cs b/src/Paramore.Brighter/Tasks/BrighterSynchronizationContext.cs index b58dac4f4..134a17cce 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); } From 617f505b7f76faa5d753e9ac29570b0abaad68b1 Mon Sep 17 00:00:00 2001 From: Ian Cooper Date: Tue, 31 Dec 2024 18:24:29 +0000 Subject: [PATCH 2/2] fix: use a new thread if the context has closed --- .../BrighterSynchronizationContextsTests.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/Paramore.Brighter.Core.Tests/Tasks/BrighterSynchronizationContextsTests.cs b/tests/Paramore.Brighter.Core.Tests/Tasks/BrighterSynchronizationContextsTests.cs index 92f3108fd..c3c9f2c2f 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()