https://kotlinlang.org logo
#coroutines
Title
# coroutines
z

zak.taccardi

12/15/2017, 4:06 PM
my company needs a future type (on Java 7, so no
CompletableFuture<T>
. But we have mixed kotlin/java code. Does that mean we cannot use
Deffered<T>
?
r

r4zzz4k

12/15/2017, 4:41 PM
The most important method of
Deferred<T>
is
await()
, which is
suspend
function. As you may know, you can't invoke such functions from Java code. So I believe your best bet is to use
kotlinx-coroutines-guava
module which binds Guava's
ListenableFuture
(available for Java 7) and coroutines(https://github.com/Kotlin/kotlinx.coroutines/tree/master/integration/kotlinx-coroutines-guava). If the size of the Guava is a concern and it's not used in the project otherwise, it might be an option to pull in
streamsupport
library (https://github.com/streamsupport/streamsupport) -- it has backport of
CompletableFuture<T>
for previous Java versions. You'll have to provide coroutine wrappers yourself though, because package name is different, so
kotlinx-coroutines-jdk8
won't work as is. You might be able to just repackage jar changing package name.
6 Views