

( assert ( > ( with-meta ( cancel-on-exception f cancel-fn) ) ( swap! events update-in #( conj ( or % ) f)) Scheduler using `with-clock`, and can be advanced to a particular time via `advance`. "Creates a clock designed for testing scheduled behaviors. ^Runnable ( cancel-on-exception f cancel-fn) schedule e f ( long ( * interval-millis 1e3)) TimeUnit/MICROSECONDS) Total: once initially, as the initial delay is 0 and 5 times for every 1 ms Rather, for each scheduledĮvent within `` the clock is reset to the time of the eventįor example, if you have a periodic function scheduled withĪnd advance the clock by 5, the counter will be incremented 6 times in "Advances the mock clock by the specified interval of `time`.Īdvancing the clock is a continuous action - the clock doesn't just jumpįrom `now` to `new-now = (+ (now clock) time)`.

( now "Returns the current time for the clock ") ( re/declare success! error! deferred realized? chain connect) add cal ( unit->calendar-unit unit) value) "Takes a `timestamp`, and adds `value` multiples of `unit` to the value. ( let [^Calendar cal ( doto ( Calendar/getInstance ( TimeZone/getTimeZone "UTC ")) ( assert ( contains? unit->calendar-unit unit)) "Takes a `timestamp`, and rounds it down to the nearest even multiple of the `unit`. #( -> ( take % units) ( map unit->calendar-unit)) Units ( -> sorted-units ( partition 2) ( map first)) Unit->calendar-unit ( apply hash-map sorted-units) ( let [sorted-units [ :millisecond Calendar/MILLISECOND "Takes a duration in milliseconds, and returns a formatted stringĭescribing the interval, i.e. ( let [intervals ( partition 2 [ "d " ( days 1) "Converts frequency -> period in milliseconds " In practice, the methods here are not necessary to use Manifold effectively - `ferred/timeout` and `manifold.stream/periodically` are more directly useful - but they are available for anyone who should need them.

:doc "This namespace contains methods for converting units of time, with milliseconds as the base representation, and for deferring execution of functions to some time in the future.
