MutexProvider

internal class MutexProvider<K>

Creates a mutex associated with a key and locks it so that there's only one execution going for a given key at a given time. When the lock for the given key is executed for the first time, it will create a new entry in the map and lock the mutex. When another lock is executed for the same key while it's locked, it will increase the count and lock the mutex so that it'll wait and execute after the first execution unlocks the mutex. The count is there to keep the mutex in the map as long as it's needed. After the last unlock, the mutex is removed from the map.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun doesLockCurrentlyExist(key: K): Boolean
Link copied to clipboard
suspend fun <T> withLock(key: K, onWaitingToUnlock: () -> Unit = {}, action: suspend () -> T): T