Maybe interesting in this context is that Brian Goetz thinks that project Loom will make reactive programming obsolete.
I still think that couroutines might not be beneficial compared to the simpler and less invasive virtual threads in many scenarios. It looks like Pivotal, the company behind Spring, has the same opinion: Embracing Virtual Threads
I donât think anyone is saying that virtual threads are a bad idea, just that coroutines as they are implemented in Kotlin are much more than just âcheap concurrencyâ.
You canât do this with virtual threads:
// Cheap, lazy, synchronous iterator
val fibonacci = sequence {
yield(1)
var cur = 1
var next = 1
while (true) {
yield(next)
val tmp = cur + next
cur = next
next = tmp
}
}
fun main(args: Array<String>) {
println(fibonacci.take(10).joinToString())
}
Coroutines also make Arrowâs bind operator possible.
Virtual threads do not have a concept of hierarchy, which is extremely useful (on the client side: multiple requests originate from a component in React or Compose, when the component goes out of the screen all requests related to it are automatically cancelled; on the server side: multiple sub-tasks can be started for a single client request and if any of them fail youâre guaranteed the others are killed). It allows the entire codebase to use asynchronous methods without breaking the applicationâs lifecycle.
And most importantly, theyâre multiplatform. JavaScript doesnât have threads (virtual or otherwise) but still needs concurrency, Native doesnât have virtual threads, etc.