althaf
08/31/2022, 4:14 PMoverride suspend fun isLoginSessionValid(): Flow<Result<Boolean>> = flow {
ParseUser.getCurrentUser()?.let { parseUser ->
if (!parseUser.isAuthenticated)
cleanupOnLogout()
emit(Result.success(parseUser.isAuthenticated))
} ?: kotlin.run {
cleanupOnLogout()
emit(Result.success(false))
}
}Francesc
08/31/2022, 4:21 PMsuspend function that returns a flow. These don't go together. You are emitting a single value, so just make this a suspend function
override suspend fun isLoginSessionValid(): Result<Boolean> {
ParseUser.getCurrentUser()?.let { parseUser ->
if (!parseUser.isAuthenticated)
cleanupOnLogout()
return Result.success(parseUser.isAuthenticated)
} ?: kotlin.run {
cleanupOnLogout()
return Result.success(false)
}
}hfhbd
08/31/2022, 4:22 PM?:. And you should not rely on let ?: run to run another action. because the last expression in the let lambda could change the execution of runAditya Kurkure
08/31/2022, 4:22 PMif ( ParseUser.getCurrentUser()?.isAuthenticated == true) {
// emit success here
} else{
// handle case when null or false here assuming you want to do the same thing when the value is null or false
}Klitos Kyriacou
08/31/2022, 4:29 PMoverride suspend fun isLoginSessionValid() = Result.success(
ParseUser.getCurrentUser()?.isAuthenticated == true || run { cleanupOnLogout(); false }
)hfhbd
08/31/2022, 4:29 PMResult at all 😄
override suspend fun isLoginSessionValid(): Boolean {
val parseUser = ParseUser.getCurrentUser()
return if (parseUser != null && parseUser.isAuthenticated) true
else {
cleanupOnLogout()
false
}
}phldavies
08/31/2022, 4:46 PMoverride suspend fun isLoginSessionValid() = (ParseUser.getCurrentUser()?.isAuthenticated ?: false)
.also { if(!it) cleanupOnLogout() }
.let { Result.success(it) } // if really needed
Arguably, making the code shorter shouldn’t necessarily be the goal but instead making it clear and concise.