Hello all, I am new at kotlin, Is this the correc...
# coroutines
d
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
Yup, they execute sequentially, one won't start after the previous one has finished.
u
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
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
true, but logging out in a scope that regularly gets canceled right after it’s started should still be avoided 😉