~ruther/NosSmooth

5c30f9fcdea2c1e5f357d4a054edcc884d586d5d — Rutherther 2 years ago 1e02f27
fix(core): do not wait in case state was already reached
1 files changed, 5 insertions(+), 2 deletions(-)

M Core/NosSmooth.Core/Contracts/DefaultContract.cs
M Core/NosSmooth.Core/Contracts/DefaultContract.cs => Core/NosSmooth.Core/Contracts/DefaultContract.cs +5 -2
@@ 199,6 199,11 @@ public class DefaultContract<TData, TState, TError> : IContract<TData, TState>
            );
        }

        if (CurrentState.CompareTo(state) >= 0)
        { // already reached.
            return Data;
        }

        _waitingFor = state;
        _unregisterAtWaitingFor = unregisterAfter;
        _waitCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(ct);


@@ 281,8 286,6 @@ public class DefaultContract<TData, TState, TError> : IContract<TData, TState>
        }
        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();


Do not follow this link