What would be the idiomatic Kotlin way to invoke a...
# coroutines
r
What would be the idiomatic Kotlin way to invoke a function exactly once? (an equivalent of Golang's sync.Once).
s
I'm not familiar with Go, but it sounds like the function you mentioned might be similar to lazy()
👍 1
r
I spotted lazy{}, but couldn't see a way to do suspending operations with it
s
Just combine it with `async`:
Copy code
val myResult by lazy { myScope.async { doStuff() } }
val stuff = myResult.await()