Lightweight scheduling library.
Lightweight scheduling library.
(cancel-next! sched)
(cancel-next! sched interrupt?)
Cancels the next upcoming chime, potentially abruptly,
as it may have already started. The rest of the schedule
will remain unaffected, unless the interruption is handled
by the error-handler (i.e. InterruptedException
), and it
returns falsey, or throws (the default one returns true).
Returns true if already cancelled.
Cancels the next upcoming chime, potentially abruptly, as it may have already started. The rest of the schedule will remain unaffected, unless the interruption is handled by the error-handler (i.e. `InterruptedException`), and it returns falsey, or throws (the default one returns true). Returns true if already cancelled.
(cancel-next?! sched)
Like cancel-next!
, but only if the next task
hasn't already started (millisecond tolerance).
Like `cancel-next!`, but only if the next task hasn't already started (millisecond tolerance).
(chime-at times f)
(chime-at times
f
{:keys [error-handler on-finished thread-factory clock drop-overruns?]
:or {error-handler default-error-handler
thread-factory default-thread-factory
clock times/*clock*}})
Calls <f> with the current time, at every time in the <times> sequence.
(:require [chime.schedule :as chime])
(:import [java.time Instant])
(let [now (Instant/now)]
(chime/chime-at
[(.plusSeconds now 2)
(.plusSeconds now 4)]
(fn [time]
(println "Chiming at" time)))
If one of those times is in the past (e.g. by accident), or a job spills over to the next time (i.e. overunning), it will (by default) be scheduled with no delay (i.e. 'push-forward' semantics). If you don't want that to happen, use the <drop-overruns?> option (i.e. 'catch-up' semantics).
Providing a custom <thread-factory> is supported, but optional (see default-thread-factory
).
Providing a custom <clock> is supported, but optional (see times/*clock*
).
Providing a custom (1-arg) error-handler
is supported, but optional (see default-error-handler
).
Return truthy from this function to continue the schedule (the default), or falsy to shut it down.
Returns an AutoCloseable that you can .close
in order to shutdown the schedule.
You can also deref the return value to wait for the schedule to finish.
When the schedule is either manually cancelled or exhausted, the <on-finished> callback will be called.
Calls <f> with the current time, at every time in the <times> sequence. ``` (:require [chime.schedule :as chime]) (:import [java.time Instant]) (let [now (Instant/now)] (chime/chime-at [(.plusSeconds now 2) (.plusSeconds now 4)] (fn [time] (println "Chiming at" time))) ``` If one of those times is in the past (e.g. by accident), or a job spills over to the next time (i.e. overunning), it will (by default) be scheduled with no delay (i.e. 'push-forward' semantics). If you don't want that to happen, use the <drop-overruns?> option (i.e. 'catch-up' semantics). Providing a custom <thread-factory> is supported, but optional (see `default-thread-factory`). Providing a custom <clock> is supported, but optional (see `times/*clock*`). Providing a custom (1-arg) `error-handler` is supported, but optional (see `default-error-handler`). Return truthy from this function to continue the schedule (the default), or falsy to shut it down. Returns an AutoCloseable that you can `.close` in order to shutdown the schedule. You can also deref the return value to wait for the schedule to finish. When the schedule is either manually cancelled or exhausted, the <on-finished> callback will be called.
(next-chime-at sched)
(next-chime-at sched clock)
Returns the (future) ZonedDateTime
when the next chime will occur,
or nil if it has already started (millisecond tolerance).
Returns the (future) `ZonedDateTime` when the next chime will occur, or nil if it has already started (millisecond tolerance).
(shutdown! sched)
Gracefully closes the entire schedule (per pool.shutdown()
).
If the next task hasn't started yet, it will be cancelled,
otherwise it will be allowed to finish.
Gracefully closes the entire schedule (per `pool.shutdown()`). If the next task hasn't started yet, it will be cancelled, otherwise it will be allowed to finish.
(shutdown-now! sched)
(shutdown-now! sched interrupt?)
Attempts a graceful shutdown (per shutdown!
), but if the latest task
is already happening attempts to interrupt it. Semantically equivalent
to pool.shutdownNow()
when called with <interrupt?> = true (the default).
Attempts a graceful shutdown (per `shutdown!`), but if the latest task is already happening attempts to interrupt it. Semantically equivalent to `pool.shutdownNow()` when called with <interrupt?> = true (the default).
(until-next-chime sched)
(until-next-chime sched time-unit)
Returns the remaining time (in millis by default)
until the next chime (via ScheduledFuture.getDelay()
).
Returns the remaining time (in millis by default) until the next chime (via `ScheduledFuture.getDelay()`).
(wait-for sched)
(wait-for sched timeout-ms timeout-val)
Blocking call for waiting until the schedule finishes, or the provided <timeout-ms> has elapsed.
Blocking call for waiting until the schedule finishes, or the provided <timeout-ms> has elapsed.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close