Table of Contents

Class SemaphoreExecutor<TKey>

Namespace
Tharga.Toolkit
Assembly
Tharga.Toolkit.Standard.dll

Allows execution of one thread at a time, for a specific key. Threads with different keys will be executed in parallel. Thread with the same key will be executed one at a time.

public class SemaphoreExecutor<TKey>

Type Parameters

TKey
Inheritance
SemaphoreExecutor<TKey>
Inherited Members
Extension Methods

Remarks

Each instance has its own locks, so code that must not run at the same time for the same key has to share one instance. The lock is not reentrant: an action that calls ExecuteAsync<T>(TKey, Func<Task<T>>) on the same instance with the same key waits for itself.

Methods

ExecuteAsync<T>(TKey, Func<Task<T>>)

public Task<T> ExecuteAsync<T>(TKey key, Func<Task<T>> action)

Parameters

key TKey
action Func<Task<T>>

Returns

Task<T>

Type Parameters

T