Igor Kolomiets
06/21/2022, 5:45 PMpublic interface FibonacciService {
CompletableFuture<Long> nextFibonacci(Long number);
}
In my Kotlin code, I’d like to add extension function to this interface to expose nextFibonacci
method as suspended function:
suspend fun FibonacciService.nextFibonacci(number: Long): Long = nextFibonacci(number).asDeferred().await()
Unfortunately, the code above doesn’t work, because nextFibonacci
extension is shadowed by interface original method (I have to rename it to something different, e.g. coNextFibonacci
, suspndNextFibonacci
, deferredNextFibonacci
?). Is there a conventional prefix (or suffix) to distinguish suspendible variants?
Also, would it be nice if Kotlin language allowed for suspend
variants in cases like this (presence of CoroutineScope would allow to figure out which one to use)?ephemient
06/21/2022, 6:10 PMCompletableFuture.await()
directlyIgor Kolomiets
06/21/2022, 8:04 PMCompletableFuture.await()
as of right now, I don’t need it. Thank you! Still, I guess, should there be a need to do something special with CoroutineContext or exception handling a dedicated suspend
function may be required.tseisel
06/22/2022, 5:25 PM@JvmName
should do the trickIgor Kolomiets
06/22/2022, 8:20 PM@JvmName
- it didn’t work (inside CoroutineContext, original method that returns CompletableFuture<Long>
is resolved, not the extension with the same name).andylamax
06/23/2022, 9:29 PM@LowPriorityOnOverideResolutionAmbiguity