Fix NamedSemaphore naming

This commit is contained in:
Dude so hot authored and renovate[bot] committed 2024-10-21 20:54:37 +08:00
1 parent 0dfee513f4
commit 62477dac87
1 file changed
+5 -5
@@ -26,15 +26,15 @@ class NamedSemaphore<K>(val permits: Int) {
}
suspend inline fun <K, R> NamedSemaphore<K>.withPermit(key: K, action: () -> R): R {
val mutex = synchronized(active) { active.getOrPut(key) { pool.borrow() }.inc() }
val semaphore = synchronized(active) { active.getOrPut(key) { pool.borrow() }.inc() }
return try {
mutex.withPermit(action)
semaphore.withPermit(action)
} finally {
synchronized(active) {
mutex.dec()
if (mutex.isFree) {
semaphore.dec()
if (semaphore.isFree) {
active.remove(key)
pool.recycle(mutex)
pool.recycle(semaphore)
}
}
}