Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.
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
67 changes: 0 additions & 67 deletions src/Chronicle/Async/KeyedLocker.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Chronicle/Chronicle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="6.3.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Scrutor" Version="3.1.0" />
</ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions src/Chronicle/Managers/SagaCoordinator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Chronicle.Async;
using AsyncKeyedLock;

namespace Chronicle.Managers
{
Expand All @@ -11,7 +11,11 @@ internal sealed class SagaCoordinator : ISagaCoordinator
private readonly ISagaInitializer _initializer;
private readonly ISagaProcessor _processor;
private readonly ISagaPostProcessor _postProcessor;
private static readonly KeyedLocker Locker = new KeyedLocker();
private static readonly AsyncKeyedLocker<string> _asyncKeyedLocker = new(o =>
{
o.PoolSize = 20;
o.PoolInitialFill = 1;
});

public SagaCoordinator(ISagaSeeker seeker, ISagaInitializer initializer, ISagaProcessor processor,
ISagaPostProcessor postProcessor)
Expand Down Expand Up @@ -49,7 +53,7 @@ private async Task ProcessAsync<TMessage>(TMessage message, ISagaAction<TMessage
var saga = (ISaga)action;
var id = saga.ResolveId(message, context);

using (await Locker.LockAsync(id))
using (await _asyncKeyedLocker.LockAsync(id.Id).ConfigureAwait(false))
{
var (isInitialized, state) = await _initializer.TryInitializeAsync(saga, id, message);

Expand Down