Is there a way to co-ordinate coroutines using on Dispatchers with wait statements across codeblocks

42 Views Asked by At

I have a situation with a lot of callbacks, specifically onCompleteListeners from Firebase Auth. First I am getting a Firebase Auth object using an SDK. However there is no other option but to use an onCompleteListener. Then I need to use another onCompleteListener to get the auth token for it. I have a use case with a suspend operator function that tries to do a Firebase realtime database call using a REST API. The problem is my code is getting really ugly.

What would be best would be to do something like you could do with Futures. I have seen async & await statements in other examples. What would be best is if I could use something like tags and awaits so I can await on some sections. If not I can use observers.

0

There are 0 best solutions below