Hi everyone I'm working with Kafka via Kotlin and ...
# coroutines
a
Hi everyone I'm working with Kafka via Kotlin and we want to transform its
Future
implementation (https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/producer/internals/FutureRecordMetadata.java) as
Deferred
. Could this be a solution?
Copy code
fun <T> Future<T>.asDeferred(): Deferred<T> {
    return GlobalScope.async(<http://Dispatchers.IO|Dispatchers.IO>) {
        get()
    }
}
@rocketraman suggested to follow also this solution: https://stackoverflow.com/questions/50793362/how-to-use-suspendcoroutine-to-turn-java-7-future-into-kotlin-suspending-functio#answer-52901712 Which of these two is the most correct?
h
Maybe just wrap it in
CompletableFuture
and use coroutine jdk8 wrappers
a
Why add a java layer?
r
Wrapping a regular
Future
in
CompletableFuture
doesn't solve the underlying problem... whenever and wherever that
get
is called, its gonna block. That's why I suggested he use the IO dispatcher for the
get
.
138 Views