A minimal Kotlin/JVM Coroutines runtime.
======= .kt Line Counter =======
Lines: 478
Non-empty lines: 392
runBlocking {}Run coroutines in a coroutine scope. It starts an event loop internallylaunch {}Launch a new coroutine. It returns a taskawait(),cancel()Control launched coroutine taskswithContext {}Switch to another coroutine context. It just callslaunchandawaits the resultdelay()Delay the coroutine execution. It reschedules the current task to the event queueDispatchersDecide the thread(pool) to run coroutines (Maindispatcher is not supported yet)
- Flows and channels
- Exception handler
- Parent-children job support
- Concurrency primitives (Mutex, Semaphore, etc.)
- Start strategies
- Testing mechanisms
- ...
NO. It's for learning purposes, it lacks features, can be buggy, has no tests, and isn't optimized. So don't use it for other purposes.
fun main(): Unit = runBlocking {
val count = 100_000
val done = AtomicInteger(0)
val millis = measureTimeMillis {
val tasks = List(count) {
launch {
delay(3000)
done.incrementAndGet()
}
}
tasks.forEach { it.join() }
}
check(done.get() == count)
println("$count Coroutines finished in ${millis}ms")
}fun main(): Unit = runBlocking {
val tasks = listOf(
launch {
delay(1000)
"Hello"
},
launch {
delay(1500)
"World"
}
)
val elapsed = measureTimeMillis {
println(tasks.awaitAll().joinToString())
}
check(elapsed <= 1600)
}fun main(): Unit = runBlocking {
val thread = Thread.currentThread()
withContext(Dispatchers.Default) {
check(thread != Thread.currentThread())
}
}