dave08
suspend fun <K: Any, V> AsyncCache.getSuspending(key: K): V { val outerContext = coroutineContext return get(key) { k, executor -> val innerContext = outerContext + Job() + executor.asCoroutineDispatcher() CoroutineScope(innerContext).async { loadValue(k) // loadValue is a suspend function defined elsewhere }.asCompletableFuture() }.await() }
Dominaezzz
suspend fun <K: Any, V> AsyncCache.getSuspending(key: K): V { val outerContext = coroutineContext return get(key) { k, executor -> val innerContext = outerContext + Job() + executor.asCoroutineDispatcher() GlobalScope.async(innerContext) { loadValue(k) // loadValue is a suspend function defined elsewhere }.asCompletableFuture() }.await() }
suspend fun <K: Any, V> AsyncCache.getSuspending(key: K): V { val outerContext = coroutineContext return get(key) { k, executor -> val innerContext = outerContext + Job() + executor.asCoroutineDispatcher() GlobalScope.future(innerContext) { loadValue(k) // loadValue is a suspend function defined elsewhere } }.await() }
GlobalScope
innerContext
CoroutineScope
A modern programming language that makes developers happier.