Got a question: - I have three `suspend` operatio...
# coroutines
i
Got a question: - I have three
suspend
operations, each can be called independently:
foo1(list)
,
foo2(list)
and
foo3(list)
- each function changes state of items in list -
foo1
just makes request to the server and returns updated list (updates 1 step) -
foo2
calls
foo1
and then with combined result makes a request (updates 2 steps) -
foo3
calls
foo2
, combines result and makes a request (updates 3 steps) Problem is,
foo2
needs to gather data (SMS-code) via DialogFragment. Is there a way to build a continuous pipeline, so the
foo3
can continue its flow after
foo2
called a dialog, gathered input and returned?
e
Yes
👍 2
i
that wasn't helpful😐
e
Sorry, I’m not an Android developer, so I don’t know the specific code you should write. I just know it is possible, because you can always call
suspendCancellableCoroutine { … }
and then resume the coroutine on whatever callback you receive when the dialog had gathered input and returned. Alternatively, you can create a
CompletableDeferred
, open the dialog, and then call
deferred.await()
in your suspending function, arranging it so that you call
deferred.complete(data)
when you have some
data
from your dialog to be processed in the subsequent steps.
i
wow that's a lot of insight, thank you!
g
suspendCancellableCoroutine works fine for this use case, we have a suspending abstraction for dialogs in out project
i
How does it look like? I ended up with CompletableDeferred