The first part of the problem is that the original method calls the
Callable
in a synchronous way. It blocks its current thread in order to get the value, so there is no way you can provide this value asynchronously and lazily at the same time. The solution for this part would be to use `runBlocking`:
fun get(key: K, valueLoader: suspend () -> V) = get(key, Callable { runBlocking { valueLoader() } })
You wanted your new function to be
suspend
probably because you want to express the asynchronism for this. The problem is that the original
get
is synchronous, so you cannot really wait for its value in a suspending way. With
runBlocking
, you don't really have to anyway.