Nikola Milovic
01/11/2020, 4:13 PMfun Login(email: String, password: String): TaskResult {
var taskResult = TaskResult.LOADING
firebaseAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener {
if(it.isSuccessful){
taskResult = TaskResult.SUCCESS
}
}
return taskResult // THIS TRIGGERS BEFORE THE ONCOMPLETELISTENER, so I always get TaskResult.Loading back
}
I am also looking to run this in a coroutineRichard Phol
01/11/2020, 4:35 PMsuspend fun login(...): TaskResult = suspendCoroutine { cont ->
firebaseAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener {
if (it.isSuccessful) {
taskResult = TaskResult.SUCCESS
cont.resume(taskResult)
}
}
}
Adam Powell
01/11/2020, 4:42 PMsuspendCancellableCoroutine
so that you can resume things based on job cancellation; firebase Task
doesn't support cancelling the actual work but you can clean up your own code at leastNikola Milovic
01/11/2020, 4:45 PMAdam Powell
01/11/2020, 4:47 PMTask
itself doesn't support it but some rare firebase operations support passing a cancellation token forward and you can wire that up to the coroutines cancellation mechanism when it's available. It's not very consistent.)