Was wondering if there some more idiomatic ways to...
# coroutines
t
Was wondering if there some more idiomatic ways to accomplish :
Copy code
fun scheduleRefresh() {
	job?.cancel()
	job = launch {
		while (isActive) {
			val newRefreshTime = getARefreshTime()
			if (newRefreshTime == 0) {
				break
			}
			delay(newRefreshTime)
			doSomething()
		}
	}
}
g
scheduleRefresh can be Flow with stream of refresh events, so you can apply mapLatest on it
👍 1
t
I'm not sure I see all the part
n
can you use a
ticker
?
t
The delay is dynamic, the code works, just wondering if there was better way to handle such dynamic pooling scenario
k
if the part that seems unintuitive to you is the manual cancellation of the job, you could make the variable that houses the job
Delegates.observable
and cancel the prior job every time a new value is set.