Reference

IConcurrencyLimiter

Package Trax.MediatorNamespace Trax.Mediator.Services.ConcurrencyLimiterSource IConcurrencyLimiter.cs, ConcurrencyLimiter.cs

The gate behind the concurrency limits. ITrainExecutionService.RunAsync acquires a permit after authorizing the caller and reading the input, and releases it when the run ends. Queued work does not pass through it. The limits are configured on the mediator builder, not through this interface.

Signature

namespace Trax.Mediator.Services.ConcurrencyLimiter;
 
public interface IConcurrencyLimiter
{
    Task<IDisposable> AcquireAsync(string trainFullName, CancellationToken ct);
}

Parameters

ParameterTypeDescription
trainFullNamestringThe train interface's FullName, the canonical train name
ctCancellationTokenCancels the wait; throws OperationCanceledException without taking a slot

Returns

A permit. Disposing it releases every slot it holds; disposing it twice is safe.

Behavior

  • Waits asynchronously while a limit is reached. It never rejects.
  • Takes the per-train, per-principal and global limits in that order, so two runs cannot deadlock on each other's slots.
  • The principal is whatever ICurrentPrincipalProvider returns at the time of the call.
  • A limit that is not configured is skipped.

Registered services

AddMediator registers the default ConcurrencyLimiter as a singleton, built from MediatorConfiguration, the [TraxConcurrencyLimit] attributes discovery found and the registered ICurrentPrincipalProvider. A replacement registered after AddMediator takes its place.

See also