Is there a better way to have a Deferred<T> ...
# announcements
d
Is there a better way to have a Deferred<T> where the value is provided through a function call? I'm pretty sure this has a race condition with the exception that tells you the newMap you provided was never going to be used.
Copy code
class MapboxState constructor(override val coroutineContext: CoroutineContext): CoroutineScope {
    private val mapChan = Channel<MapboxMap>(1)
    val map = async {
        mapChan.receive()
    }

    internal suspend fun registerMap(newMap: MapboxMap) {
        if (map.isCompleted) {
            throw IllegalStateException("MapState already registered to a MapboxMap")
        }
        mapChan.send(newMap)
    }
}
d
I am not sure I understand you correctly, but from your code it looks like you want
CompletableDeffered
d
Yes, thank you!