Long running tasks
ilevd opened this issue · 1 comments
Suppose we have such code:
(chime/chime-at (chime/periodic-seq (Instant/now) (Duration/ofSeconds 20))
(fn [_]
(when (has-new-task)
(long-running-task))))
We need to check if there is a new task every 20 secs, and if so, we need run long-time calculation (which can last for an hour). Then after long running task is completed, there will be a lot of (has-new-task)
calls, which would be better to avoid.
Is it possible to add a parameter to avoid such behaviour and instead run only 1 function call after long-running-task is completed? Or is it better to use another mechanism for such situation?
Hey @ilevd - it seems that you're looking for something that'll poll for new tasks every 20s or so, which admittedly is a little outside what I originally intended Chime for 😄 I'd probably have something like
(while true
(if (has-new-task)
(long-running-task)
(Thread/sleep 20000)))
;; with appropriate exception/interrupt handling if required
If you did want to use Chime, the core.async support might be more suitable - you could use the dropping-channel
example to only keep one Chime task in the queue.