ursus
07/03/2019, 8:47 AMPaulius Ruminas
07/03/2019, 8:50 AMursus
07/03/2019, 9:05 AMRepository {
fun sync() {
repoScope.launch { .. }
}
}
streetsofboston
07/03/2019, 11:48 AMjoin()
on the Job
returned by launch {...}
. This means, though, that sync()
must become suspend
.launch
, use async<Unit>
, then await()
the Unit
result or a possible Exception.Paulius Ruminas
07/03/2019, 12:33 PMright? but then sync is a normal function, how can I let vm know when sync is done, etc?Usually these kind of operations are done using channels to retrieve the result. After the sync operation is done it should send the updated data through the channel. This way if you have multiple calls to sync you will always have the most recent data in your UI since you have a single source of truth. If you really need the result then you should use
withContext()
and pass in the repo scope context. This ways the block will not be cancelled by vm destroy.ursus
07/03/2019, 6:50 PM