getOrPut

open suspend override fun getOrPut(key: K, creationFunction: suspend (key: K) -> V?): V?

Returns the value corresponding to the given key if it exists, is currently being created, a new value created by creationFunction, or null if the creation fails.

The function waits for the creation to complete if it is in progress. If the creation fails, the function returns null. Any unhandled exceptions inside the creation block will be thrown. creationFunction is NOT used as a fallback if the current creation fails.

creationFunction should return null only if the creation fails.