lazyDeferred

fun <T> lazyDeferred(action: suspend () -> T): LazyDeferred<T>

Lazily invokes action the first time await or join is called.

This action is only invoked once. The caller's coroutine is used to execute this action.

val expensive = lazyDeferred { repository.getAll() }

suspend fun getExpensive() = expensive.await()

Sources

Link copied to clipboard