Files
2022-09-29 13:49:24 +02:00

15 lines
389 B
Kotlin

import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
val semaphore = Semaphore(5, 5)
suspend fun main() {
semaphore.acquire() //reduces available permits, suspends when none available
semaphore.tryAcquire() //returns False if no permit available
semaphore.release() //releases permit, possible after acquire
semaphore.withPermit {
}
}