Join Slack
Powered by
What would be the idiomatic Kotlin way to invoke a...
# coroutines
r
rob42
11/11/2024, 6:09 PM
What would be the idiomatic Kotlin way to invoke a function exactly once? (an equivalent of Golang's
sync.Once
).
s
Sam
11/11/2024, 8:02 PM
I'm not familiar with Go, but it sounds like the function you mentioned might be similar to
lazy()
👍 1
r
rob42
11/18/2024, 9:30 AM
I spotted lazy{}, but couldn't see a way to do suspending operations with it
s
Sam
11/18/2024, 9:32 AM
Just combine it with `async`:
Copy code
val myResult by lazy { myScope.async { doStuff() } } val stuff = myResult.await()
Open in Slack
Previous
Next