Brian Estrada
05/17/2022, 7:14 AMDeferred<Int>
and then call it and complete it later by another function (Will add an example in a 🧵)fun main(args: Array<String>) {
val hashMap = HashMap<String, Deferred<Int>>()
GlobalScope.launch {
delay(2000)
println("done waiting")
requireNotNull(hashMap["test"]).asCompletableFuture().complete(5)
}
runBlocking {
val asyncThing = async {
getNumberFive()
}
hashMap["test"] = asyncThing
println(asyncThing.await())
}
}
stojan
05/17/2022, 7:32 AMCompletableDeffered
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/Brian Estrada
05/17/2022, 7:38 AMstreetsofboston
05/17/2022, 11:22 AMvar asyncThing = async(start=CoroutineStart.LAZY) { ... }