Skip to content

SingleFlightExecutor Class ​

Definition ​

Executes an asynchronous factory at most once per (T, key) while there are concurrent callers, sharing the same in-flight Task1` across callers (a "single-flight"). The in-flight entry is removed when the task completes (success, fault, or cancellation).

  • Namespace: JASE
  • Assembly: JASE.Concurrency.dll

Methods ​

NameDescription
Task<T> RunAsync(string key, Func<CancellationToken, Task<T>> factory, CancellationToken callerCancellation = null, CancellationToken sharedCancellation = null, bool keepOnSuccess = null)

Remarks ​

This is useful to deduplicate concurrent cache misses or network calls so only one request is sent upstream. The composite key is (typeof(T), string key) to prevent collisions between different result types.

Cancellation semantics: the underlying factory is started with None so that one caller's cancellation does not abort the shared work. Each caller's token cancels only their own await via System.Threading.Tasks.Task.WaitAsync(System.Threading.CancellationToken).

Exceptions from the factory are propagated to all awaiting callers. The in-flight entry is always evicted after completion so future calls can retry.