ildar.i [Android]
07/02/2020, 10:56 AMsuspend
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?elizarov
07/02/2020, 12:42 PMildar.i [Android]
07/02/2020, 4:18 PMelizarov
07/02/2020, 4:45 PMsuspendCancellableCoroutine { … }
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.ildar.i [Android]
07/02/2020, 4:54 PMgildor
07/03/2020, 2:06 PMildar.i [Android]
07/03/2020, 2:19 PM