Hello, can you please advise on good naming conven...
# coroutines
i
Hello, can you please advise on good naming convention for extension functions that convert existing Java API based on CompletableFuture to Kotlin’s suspendible variant? For example, there is Java service:
Copy code
public 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:
Copy code
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)?
e
do you need it? you can
CompletableFuture.await()
directly
👍 1
i
Actually, with
CompletableFuture.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.
t
Specifying a different name with
@JvmName
should do the trick
i
@tseisel interesting. I just checked your proposal to use
@JvmName
- it didn’t work (inside CoroutineContext, original method that returns
CompletableFuture<Long>
is resolved, not the extension with the same name).
a
yet another use case of
@LowPriorityOnOverideResolutionAmbiguity