Project Loom will make coroutines obsolete

Maybe interesting in this context is that Brian Goetz thinks that project Loom will make reactive programming obsolete.

1 Like

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.

3 Likes