Support using an executor as a function to execute a block.
This commit is contained in:
@@ -50,3 +50,11 @@ public inline fun Executor.execute(action: ()->Unit) {
|
|||||||
execute(runnable(action))
|
execute(runnable(action))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to use the executor as a function to
|
||||||
|
* execute the given block on the [[Executor]].
|
||||||
|
*/
|
||||||
|
public inline fun Executor.invoke(action: ()->Unit) {
|
||||||
|
execute(runnable(action))
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package concurrent
|
||||||
|
|
||||||
|
import kotlin.concurrent.*
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
import org.junit.Test as test
|
||||||
|
|
||||||
|
import java.util.concurrent.*
|
||||||
|
import java.util.concurrent.TimeUnit.*
|
||||||
|
|
||||||
|
class ThreadTest {
|
||||||
|
test fun scheduledTask() {
|
||||||
|
|
||||||
|
val pool = Executors.newFixedThreadPool(1).sure()
|
||||||
|
val countDown = CountDownLatch(1)
|
||||||
|
pool {
|
||||||
|
countDown.countDown()
|
||||||
|
}
|
||||||
|
assertTrue(countDown.await(2, SECONDS), "Count down is executed")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user