if I have a long running task which I'm collecting...
# getting-started
m
if I have a long running task which I'm collecting with
Copy code
longRunningTask().collect{
   // ...
}
is there a way of canceling in the middle of the collecting? Like: I wan the function to finish itself and stop doing what it was doing
s
You could consider using
transformWhile
which lets you return
true
or
false
to indicate whether you want to continue collecting the flow
👀 1
I’m not sure why
collectWhile
(which exists) isn’t a public function 🤔 but
transformWhile { … }.collect()
achieves the same thing
🧐 1
m
from what you suggested, looking at the docs, we have
takeWhile
👍 1
w
what type* does
longRunningTask
return?
m
just a String
s
A String, or a
Flow<String>
?
🙏 1
m
Flow<String>
👍 1
s
Just checking 😄
m
sometimes I'm lazy to explain things, my bad
since the condition in my case is to check whether a new message arrived in a channel,
channel.isEmpty()
, the
takeWhile{ channel.isEmpty }
seems to be working
👍 1
🐕 2