run

suspend fun run(key: K, block: suspend () -> T): T

Runs block for key, or joins the flight that already runs for an equal key.

The caller that starts the flight runs block in its own coroutine context. A joining caller only waits. Every caller gets the same value, or the same exception, thrown as it is. A timeout of a withTimeout inside block is such a shared exception.

Cancellation. When the caller that runs block is cancelled, the flight stops. The joining callers do not get that cancellation: they start a new flight instead. When a joining caller is cancelled, only its own wait stops. A cancelled flight always frees its key.

Throws

if block, or a coroutine started in it, calls run with an equal key. That call would wait for itself forever.