Is there a way to return value from a coroutine scope? for example like this:
suspend fun signUpUser(signUpData : SignUpUserRequest) : User {
CoroutineScope(Dispatchers.IO).launch() {
val response = retrofitInstance.socialSignUP(signUpData)
if (response.success) {
obj = response.data
} else {
obj = response.message
}
}.invokeOnCompletion {
obj = response.message
}
return obj
}
问题是,只要调用了signupUser函数,就立即返回obj suspend语句,而不是使用响应值..它不是按顺序运行的,我期望的是第一个响应出现,然后函数返回obj,但它没有发生.为什么?
I tried run blocking, it served the purpose but is there better approach to do same task without run blocking? or is it alright?
Thanks in advance!