Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Saga/src/Erm.Messaging.Saga/Erm.Messaging.Saga.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="6.3.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Erm.Core" Version="0.2.4" />
Expand Down
77 changes: 0 additions & 77 deletions src/Saga/src/Erm.Messaging.Saga/KeyedLocker.cs

This file was deleted.

11 changes: 8 additions & 3 deletions src/Saga/src/Erm.Messaging.Saga/SagaCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Erm.Messaging;
using AsyncKeyedLock;

namespace Erm.Messaging.Saga;

Expand All @@ -12,7 +13,11 @@ internal sealed class SagaCoordinator : ISagaCoordinator
private readonly ISagaInitializer _initializer;
private readonly ISagaProcessor _processor;
private readonly ILogger<SagaCoordinator> _logger;
private static readonly KeyedLocker Locker = new();
private static readonly AsyncKeyedLocker<Guid> Locker = new(o =>
{
o.PoolSize = 20;
o.PoolInitialFill = 1;
});

public SagaCoordinator(ISagaLocator locator,
ISagaInitializer initializer,
Expand Down Expand Up @@ -58,7 +63,7 @@ private async Task Process<TMessage>(
var sagaId = saga.GetSagaId(context, envelope, action is ISagaStartAction<TMessage>);
using (_logger.BeginScope("Saga {SagaType}[{SagaId}]", saga.GetType().FullName, sagaId))
{
using (await Locker.Lock(sagaId))
using (await Locker.LockAsync(sagaId).ConfigureAwait(false))
{
var (initialized, state) = await _initializer.TryInitialize<TMessage>(saga, sagaId).ConfigureAwait(false);
if (!initialized)
Expand All @@ -77,4 +82,4 @@ private async Task Process<TMessage>(
}
}
}
}
}