Question:
userId
which is a variable that I defined in the first line of the function, when I place the return block outside the coroutine scope, it returns an empty string, how do I return it inside the scope so it can run when the coroutine is finished, or any other way to return after the coroutine is finishedAnswer:
In order to make a function returns a pending value; it should be asuspend
function to return the value asynchronously.Then, instead of the
launch
builder, the async/await
builder can be used to return a Deferred
value.await()
waits until it’s assigned a value by the CoroutineApplying that in code:
If you have better answer, please add a comment about this, thank you!