DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="4.14.1" />

 AsyncCorrelationSource<TKey, TValue>

public class AsyncCorrelationSource<TKey, TValue>
Represents pub/sub synchronization primitive when each event has unique identifier.
public AsyncCorrelationSource(int concurrencyLevel, IEqualityComparer<TKey> comparer = null)

Initializes a new event correlation source.

public bool Pulse(TKey eventId, ref Result value)

Informs that the event is occurred.

public bool Pulse(TKey eventId, ref Result value, out object userData)

Informs that the event is occurred.

public void PulseAll(TValue value)

Notifies all active listeners.

public void PulseAll(Exception e)

Raises the exception on all active listeners.

public void PulseAll(CancellationToken token)

Cancels all active listeners.

public ValueTask<TValue> WaitAsync(TKey eventId, object userData, TimeSpan timeout, CancellationToken token = default)

Returns the task linked with the specified event identifier.

public ValueTask<TValue> WaitAsync(TKey eventId, TimeSpan timeout, CancellationToken token = default)

Returns the task linked with the specified event identifier.

public ValueTask<TValue> WaitAsync(TKey eventId, CancellationToken token = default)

Returns the task linked with the specified event identifier.