Eliminate accidental coroutine hierarchy in the sessions cache (#1591)

This commit is contained in:
Sergey Mashkov
2020-01-28 17:59:35 +03:00
parent 18351b426a
commit d81f76b017

View File

@@ -33,7 +33,11 @@ internal class BaseCache<in K : Any, V : Any>(val calc: suspend (K) -> V) : Cach
override suspend fun getOrCompute(key: K): V {
val coroutineContext = coroutineContext
return container.computeIfAbsent(key) { CoroutineScope(coroutineContext).async(Dispatchers.Unconfined) { calc(key) } }.await()
return container.computeIfAbsent(key) {
CoroutineScope(coroutineContext.minusKey(Job)).async(Dispatchers.Unconfined) {
calc(key)
}
}.await()
}
override fun peek(key: K): V? = container[key]?.let { if (!it.isActive) it.getCompleted() else null }