https://kotlinlang.org logo
Title
u

ursus

03/28/2022, 10:43 PM
how would you pause a
timer
type flow? it’s not really idiomatic, is it? or maybe akin to backpressure, i.e. downstream telling upstream to stop?
r

Richard Gomez

03/29/2022, 2:24 AM
What are you trying to accomplish? It seems like you'd be mixing coroutines and Java concurrency, which could be a bit awkward. It might be easier to cancel the timer and create a new one instead.
u

ursus

03/29/2022, 11:17 AM
Instagram stories ui .. the timer which auto-advances and can be paused via tap-n-hold
n

Nick Allen

03/29/2022, 5:23 PM
Do you mean something like?:
timerEnabled.transformLatest { if (it) emitAll(timer) }
u

ursus

03/29/2022, 6:58 PM
@Nick Allen can you do a bit more? I see youre only allowing timer if timerEnabled, but that would mean its filtering, not pausing right? i.e. 1 2 3 …. 10 11 12?
n

Nick Allen

03/29/2022, 7:12 PM
It's not filtering, it's re-subscribing everytime it turns true. If timer is "hot" then it's basically a filter. If "cold", then it's more like 1,2 3 ... paused ... 1, 2, 3 (resubscribing restarts the flow) Perhaps you want to subscribe once and not skip values but just wait for timer to become unpaused again?
timer.onEach { timerEnabled.first { it } }
Don't use instagram so I know nothing of what's implied by that. Does your timer emit an index? Should pausing not skip values? If you tap mid-interval do you need resuming the timer to wait for the remaining part of the interval?
u

ursus

03/29/2022, 9:11 PM
@Nick Allen yes pause and resume, and yes Id ideally want a stream of floats 0..1 here is a video, watch the progress bar at the top btw when it pauses its me holding the screen (google removed taps from screenrecording ughh), and resumes when I release