Is there an in built way of doing something like: ...
# coroutines
t
Is there an in built way of doing something like:
Copy code
do {
   invoke a suspending method that increments a counter or something
} while {
   another suspending method suspends
}
Where both invocations are simultaneously suspending and executing. This would be similar to
Flow.takeWhile
but without using the flow API. Or even a clever way to do this with
coroutineScope
and
async
operators
Syntax of what I'm trying to do:
Copy code
do {
   while(true) {
      ++counter
      delay(100)
   }
} while {
   snapshotFlow { value }
       .first { it is State.Completed }
}
So I already have flow APIs, and I can use
Flow.takeWhile
, just curious if I can do it with regular suspending methods
j
launch
the "do", cancel the returned
Job
once the "while" completes
thank you color 1
t
Ty! I thought of doing this, but I hesitated bc I assumed launching within another launch or in this case
LaunchedEffect
was off
z
that's one of the main features of coroutines, definitely not off
thank you color 1