Jakub Gwóźdź
11/08/2023, 8:08 AMCompletableFuture.asDeferred() already, but when the API you’re using is still java7-compatible, tough luck.
So far I just went with
inline fun <reified T> Future<T>.asCompletableDeferred(): Deferred<T> =
CompletableFuture.supplyAsync { this.get() }.asDeferred()
and it works, as far as I can see.
But I’d like to omit unnecessary wrapping if this is already Completable:
inline fun <reified T> Future<T>.asCompletableDeferred(): Deferred<T> =
if (this is CompletionStage<*>) this.asDeferred() else CompletableFuture.supplyAsync { this.get() }.asDeferred()
and that is going all hysterical complaining that this.asDeferred() is no longer Deferred<T> but Deferred<Any>
Why is that so and how to fix it?ephemient
11/08/2023, 8:32 AM<*>Jakub Gwóźdź
11/08/2023, 8:32 AMMyFuture : Future<Int>, CompletionStage<String> however stupid that seems…ephemient
11/08/2023, 8:32 AMJakub Gwóźdź
11/08/2023, 8:33 AMif (this is CompletionStage<T>) because then “cannot check for erased type”ephemient
11/08/2023, 8:33 AMephemient
11/08/2023, 8:34 AMJakub Gwóźdź
11/08/2023, 8:34 AMinline fun <reified T> Future<T>.asCompletableDeferred(): Deferred<T> =
if (this is CompletableFuture<T>) this.asDeferred() else CompletableFuture.supplyAsync { this.get() }.asDeferred()
is good enough…Jakub Gwóźdź
11/08/2023, 8:35 AMsend() which returns ancient Future<RecordMetadata> (I’m not sure if it is Completable, tho)