Is there any cleanup you need to do after using a ...
# coroutines
g
Is there any cleanup you need to do after using a mutex and withLock? Am I correct in guessing that withLock is doing all of that (eg, unlocking)
k
The implementation is essentially
Copy code
public suspend inline fun <T> Mutex.withLock(owner: Any? = null, action: () -> T): T {
    lock(owner)
    return try {
        action()
    } finally {
        unlock(owner)
    }
}
So yes, cleanup will happen for you.
g
Got it. Is there any way you can have a mutex with multiple locks in a pool? (eg; allow 2 concurrent coroutines or n number, etc) or would you need to have N mutexes and try locking until you found a free one?
k
You should probably use a Semaphor
g
Oh cool I didn't know that existed, thanks thats pretty cool it looks like the usage is the same with withPermit