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
}
the problem is as soon as signupUser function called, return obj suspend statement run right away, not with response value.. its not running sequentially, what I expect is first response come and then function return obj but its not happening. why?
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!