What is the principal difference between kotlin coroutines and Java 8 CompletableFuture?

Maybe there is a little misunderstanding: Kotlin in a language, so the important part of it is the syntax.

CompletableFuture and Job are these library’s classes and both are quite similar,

Coroutines allow to write suspendable method and work nicely with CompletableFuture, Job and so on.

OT

Some time ago I wrote an asynchronous implementation of recursive Quick Sort: https://github.com/fvasco/jug-2017-07/blob/master/kotlin1.1/src/main/kotlin/Main.kt#L23
The first consideration is that it is pretty small and readable.
The second one is that it can sort a big list without throw a StackOverflowError.
In such case coroutines allows iteration over recursion, again: the main difference is the syntax.

2 Likes