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:
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:
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)?