I want to be able to attach a resettable timeout o...
# coroutines
m
I want to be able to attach a resettable timeout on a job where basically I give a timeout and a channel and whenever the channel is sent a value then the timeout is reset. Is there a common practice for something like this? I was thinking of writing an extension function on Job but im not sure how i wanna approach it.
e
I’ve done this in the past with a
select
on a channel and a timeout. Here’s a sample usage in my code: https://github.com/emanguy/GitlabTimeTracker/blob/master/src/main/kotlin/controller/TimeRecordingController.kt#L99 Basically if the channel receives a value first the select immediately exits and returns the value from the channel, but if the timeout occurs first I just exit with the default
null