suspend Lazy
Like lazy, but the initializer can suspend. Read the value with SuspendLazy.get.
Example
val database = suspendLazy { openDatabase("app.db") }
suspend fun records(): List<Record> = database.get().queryAll()
// The first get() opens the database.
// Every later get() returns it at once.Content copied to clipboard
Watch out
A failure is not stored. The next SuspendLazy.get runs initializer again.
initializer must not call SuspendLazy.get on the same instance. That call throws IllegalStateException, because it would wait for itself forever.
Parameters
initializer
the code that makes the value. It runs again after each failure, and never again after the first success.