@lucid moth has a question:
how do i know when i want a launch vs a async?
because in the viewmodel i wouldve done async because presumably i wanted the value from the repo call to update the state but the docs show doing launch
1 messages · Page 1 of 1 (latest)
@lucid moth has a question:
how do i know when i want a launch vs a async?
because in the viewmodel i wouldve done async because presumably i wanted the value from the repo call to update the state but the docs show doing launch
<@&987246399047479336> please have a look, thanks.
im sorry, could u provide some context. what exactly are u talking about?
Are you talking about kotlin?
no you guys dont use coroutines?
java does not have coroutines
this is a java server. so without extra context people are confused
Coroutines are a kotlin feature. This is a java discord. So that you are talking about kotlin coroutines is context that cant be assumed.
Anyway you use launch if you want to perform a side effect asynchronously (e.g. updating state) and async if you want to calculate a value asynchronously that you can later access (e.g. 2 asynchronous http calls where you want to continue with both results).
Changed the category to Kotlin.
<@&1008423204219531294> please have a look, thanks.
You should avoid returning Deferred from a function. A plain suspend function that returns a value is plenty!
Async is for when you want to multitask multiple operations within one function, and should be added inside a function. And make sure to await it before the end of the function. Don't leak the Deferred outside of the scope of the place that async was called.