Lightweight scheduling library.
Lightweight scheduling library.
(append-absolute! sched & times)
Assuming a mutable schedule which has not finished, appends the specified <times> to it. These should be after the last one already in.
Assuming a mutable schedule which has not finished, appends the specified <times> to it. These should be *after* the last one already in.
(append-relative-to-last! sched offset-fn)
Assuming a mutable schedule which has not finished,
appends the result of (offset-fn last-chime)
into it.
Assuming a mutable schedule which has not finished, appends the result of `(offset-fn last-chime)` into it.
(cancel-current! sched)
Cancels the 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 falsy, or throws (the default one returns true).
Returns true if already cancelled.
Cancels the 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 falsy, or throws (the default one returns true). Returns true if already cancelled.
(cancel-current?! sched)
Like cancel-current!
, but only if the upcoming task
hasn't already started (with millisecond tolerance).
Like `cancel-current!`, but only if the upcoming task hasn't already started (with 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.
(current-at sched)
(current-at sched clock)
Returns the (future) ZonedDateTime
when the next chime will occur,
or nil if it has already started (with millisecond tolerance), or cancelled.
Returns the (future) `ZonedDateTime` when the next chime will occur, or nil if it has already started (with millisecond tolerance), or cancelled.
(current-cancelled? sched)
Returns true if the current chime has been cancelled,
false otherwise. A mere wrapper around future-cancelled?
.
Returns true if the current chime has been cancelled, false otherwise. A mere wrapper around `future-cancelled?`.
(is-shutdown? sched)
Returns true if the entire schedule has been shut down, false otherwise.
Returns true if the entire schedule has been shut down, false otherwise.
(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)
Attempts a graceful shutdown (per shutdown!
), but if the latest task
is already happening attempts to interrupt it. Semantically equivalent
to pool.shutdownNow()
.
Attempts a graceful shutdown (per `shutdown!`), but if the latest task is already happening attempts to interrupt it. Semantically equivalent to `pool.shutdownNow()`.
(until-current sched)
(until-current sched time-unit)
Returns the remaining time (in millis by default)
until the currently scheduled chime (via ScheduledFuture.getDelay()
).
If it has been cancelled returns -1.
Returns the remaining time (in millis by default) until the currently scheduled chime (via `ScheduledFuture.getDelay()`). If it has been cancelled returns -1.
(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