Hello all,
I am new at kotlin,
Is this the correct way that the flow is executed?
Copy code
suspend fun Logout(token: String) {
val userId = appService.currentUser!!.id ///// this will execute 1st
realm.write { ///// this will execute 2nd
var user = query<UserInfo>("_id = $0", userId).first().find()
if (user != null) {
user = findLatest(user)!!.also {
it.FCMToken.remove(token)
}
copyToRealm(user)
}
}
withContext(Dispatchers.Default) { ///// this will execute 3rd
realm.syncSession.uploadAllLocalChanges() ///// this will execute 4rd
appService.currentUser?.logOut() ///// this will execute 5th
}
}
Are they executed in a linear way?
s
streetsofboston
03/10/2023, 6:19 PM
Yup, they execute sequentially, one won't start after the previous one has finished.
u
uli
03/13/2023, 8:50 AM
Just watch out which scope this is called in. You don’t want your logout being canceled if .e.g on android your view model goes away.
e
ephemient
03/13/2023, 3:36 PM
well, this isn't transactional even if you use
NonCancellable
(what if the app is killed?), so you have some way of recovering from interruptions regardless
u
uli
03/13/2023, 4:56 PM
true, but logging out in a scope that regularly gets canceled right after it’s started should still be avoided 😉