From 5c30f9fcdea2c1e5f357d4a054edcc884d586d5d Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 19 Jan 2023 18:27:22 +0100 Subject: [PATCH] fix(core): do not wait in case state was already reached --- Core/NosSmooth.Core/Contracts/DefaultContract.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/NosSmooth.Core/Contracts/DefaultContract.cs b/Core/NosSmooth.Core/Contracts/DefaultContract.cs index d4db4d1..c80b91c 100644 --- a/Core/NosSmooth.Core/Contracts/DefaultContract.cs +++ b/Core/NosSmooth.Core/Contracts/DefaultContract.cs @@ -199,6 +199,11 @@ public class DefaultContract : IContract ); } + if (CurrentState.CompareTo(state) >= 0) + { // already reached. + return Data; + } + _waitingFor = state; _unregisterAtWaitingFor = unregisterAfter; _waitCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(ct); @@ -281,8 +286,6 @@ public class DefaultContract : IContract } if (_waitingFor is not null && _waitingFor.Value.CompareTo(CurrentState) == 0) { - IsRegistered = false; // avoid deadlock. The cancellation will trigger unregister, - // but we are inside of the lock now. _waitCancellationSource?.Cancel(); -- 2.49.0