mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
22 lines
424 B
Kotlin
22 lines
424 B
Kotlin
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
fun <T> Int.latch(op: CountDownLatch.() -> T) : T {
|
|
val cdl = CountDownLatch(this)
|
|
val res = cdl.op()
|
|
cdl.await()
|
|
return res
|
|
}
|
|
|
|
fun id(op : ()->Unit) = op()
|
|
|
|
fun box() : String {
|
|
1.latch{
|
|
id {
|
|
countDown()
|
|
}
|
|
}
|
|
return "OK"
|
|
}
|