Omkar Amberkar
07/15/2021, 4:42 PMisClosedForSend flag is still false in case I cancel the job, and there is no other way to close the channelflow that I am aware of. need some help 🙂
fun poll(gameId: String, dispatcher: CoroutineDispatcher, ) = channelFlow {
while (!isClosedForSend) {
try {
send(repository.getDetails(id))
delay(MIN_REFRESH_TIME_MS)
} catch (throwable: Throwable) {
Timber.e("Debug: error -> ${throwable.message}")
}
invokeOnClose { Timber.e("Debug: channel flow closed.") }
}
}Nick Allen
07/16/2021, 7:08 AMshareIn operator with WhileSubscribed()Omkar Amberkar
07/16/2021, 2:02 PMcallbackFlow shareIn but still, the problem of how to stop polling once there are no terminal operators, or lets say when all terminator operators are canceled.
my problem is idk how to stop polling when there are no terminal operators and start it when there is at least one.
with the above flow, it still keeps polling since the channel is still open to sendNick Allen
07/16/2021, 3:11 PMshareIn will cancel the callbackFlow and then resubscribe if a new poller starts. Your lambda will be canceled and then completely restarted.Nick Allen
07/16/2021, 3:12 PMNick Allen
07/16/2021, 3:13 PMNick Allen
07/16/2021, 3:16 PMNick Allen
07/16/2021, 3:20 PM