How to ensure that the realm.write is done and sta...
# realm
d
How to ensure that the realm.write is done and start the logout just after the realm.write is done?
Copy code
suspend fun doLogout(token: String) {
    val userId = appService.currentUser?.id

        realm.write {

            var user = query<UserInfo>("_id = $0", userId).first().find()
            if (user != null) {
                val productIndex =
                    user.FCMToken.withIndex().findLast { it.value == token }!!.index

                user = findLatest(user)!!.also {
                    it.FCMToken.removeAt(productIndex)
                }
                copyToRealm(user)
            }
        }
        appService.currentUser?.logOut()
}
👀 1