We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 84dfe5a commit 7b53e05Copy full SHA for 7b53e05
core/src/test/scala/io/aiven/guardian/kafka/Utils.scala
@@ -0,0 +1,24 @@
1
+package io.aiven.guardian.kafka
2
+
3
+import org.apache.kafka.common.KafkaFuture
4
5
+import java.util.concurrent.CompletableFuture
6
7
+object Utils {
8
9
+ // Taken from https://stackoverflow.com/a/56763206/1519631
10
+ implicit final class KafkaFutureToCompletableFuture[T](kafkaFuture: KafkaFuture[T]) {
11
+ @SuppressWarnings(Array("DisableSyntax.null"))
12
+ def toCompletableFuture: CompletableFuture[T] = {
13
+ val wrappingFuture = new CompletableFuture[T]
14
+ kafkaFuture.whenComplete { (value, throwable) =>
15
+ if (throwable != null)
16
+ wrappingFuture.completeExceptionally(throwable)
17
+ else
18
+ wrappingFuture.complete(value)
19
+ }
20
+ wrappingFuture
21
22
23
24
+}
0 commit comments