I
Size: a a a
I
DS
I
r
I
I
I
j
r
DS
public fun launchWhenCreated(block: suspend CoroutineScope.() -> Unit): Job =
launch {lifecycle.whenCreated(block)
}I
DS
public suspend fun <T> Lifecycle.whenCreated(block: suspend CoroutineScope.() -> T): T {
return whenStateAtLeast(Lifecycle.State.
CREATED, block)
}
DS
public suspend fun <T> Lifecycle.whenStateAtLeast(
minState: Lifecycle.State,
block: suspend CoroutineScope.() -> T
): T = withContext(Dispatchers.Main.immediate)
{val job = coroutineContext[Job] ?:
error("when[State] methods should have a parent job")
val dispatcher = PausingDispatcher()
val controller =
LifecycleController(this@whenStateAtLeast, minState, dispatcher.dispatchQueue, job)
try {
withContext(dispatcher, block)
} finally {
controller.finish()
}
}I
r
I
I
DS
I
r