Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 713 Bytes

README.md

File metadata and controls

24 lines (20 loc) · 713 Bytes

kotlin-coroutine-builders

Sample builders that can be used to launch coroutines (example implementation of async, await, delay, runBlocking)

The most common Uncondifed, CommonPool and Swing CoroutineInterceptors have been implemented.

    fun workUsingFutures(result: Int): CompletableFuture<Int> = async(CommonPool) {
        delay(1000)
        result
    }

    @Test
    fun sample() {
        val result = runBlocking {
            val futureList = mutableListOf<CompletableFuture<Int>>()
            for (i in 1..100_000) {
                futureList.add(workUsingFutures(1))
            }
            futureList.sumBy { it.await() }
        }

        assertEquals(100_000, result)
    }