• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to return a value inside a coroutine scope kotlin, android

Resolved: How to return a value inside a coroutine scope kotlin, android

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

That’s the function I’m using to query through firebase documents, the thing is I want to return the 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 finished

Answer:

In order to make a function returns a pending value; it should be a suspend function to return the value asynchronously.
Then, instead of the launch builder, the async/await builder can be used to return a Deferredvalue.
await() waits until it’s assigned a value by the Coroutine
Applying that in code:

If you have better answer, please add a comment about this, thank you!

android firebase kotlin kotlin-coroutines
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Resolved: GLMM with quasi-Poisson distribution

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.