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. In practice, the methods here are not necessary to use Manifold effectively - manifold.deferred/timeout
and manifold.stream/periodically
are more directly useful - but they are available for anyone who should need them.
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. In practice, the methods here are not necessary to use Manifold effectively - `manifold.deferred/timeout` and `manifold.stream/periodically` are more directly useful - but they are available for anyone who should need them.
(add timestamp value unit)
Takes a timestamp
, and adds value
multiples of unit
to the value.
Takes a `timestamp`, and adds `value` multiples of `unit` to the value.
(at timestamp f)
Schedules no-arg function f
to be invoked at timestamp
, which is the milliseconds
since the epoch. Returns a deferred representing the returned value of the function
(unwrapped if f
itself returns a deferred).
Schedules no-arg function `f` to be invoked at `timestamp`, which is the milliseconds since the epoch. Returns a deferred representing the returned value of the function (unwrapped if `f` itself returns a deferred).
(every period f)
(every period initial-delay f)
Schedules no-arg function f
to be invoked every period
milliseconds, after initial-delay
milliseconds, which defaults to 0
. Returns a zero-argument function which, when invoked,
cancels the repeated invocation.
If the invocation of f
ever throws an exception, repeated invocation is automatically
cancelled.
Schedules no-arg function `f` to be invoked every `period` milliseconds, after `initial-delay` milliseconds, which defaults to `0`. Returns a zero-argument function which, when invoked, cancels the repeated invocation. If the invocation of `f` ever throws an exception, repeated invocation is automatically cancelled.
(floor timestamp unit)
Takes a timestamp
, and rounds it down to the nearest even multiple of the unit
.
(floor 1001 :second) => 1000 (floor (seconds 61) :minute) => 60000
Takes a `timestamp`, and rounds it down to the nearest even multiple of the `unit`. (floor 1001 :second) => 1000 (floor (seconds 61) :minute) => 60000
(format-duration n)
Takes a duration in milliseconds, and returns a formatted string describing the interval, i.e. '5d 3h 1m'
Takes a duration in milliseconds, and returns a formatted string describing the interval, i.e. '5d 3h 1m'
(hz n)
Converts frequency -> period in milliseconds
Converts frequency -> period in milliseconds
(advance clock time)
Advances the mock clock by the specified interval of time
.
Advancing the clock is a continuous action - the clock doesn't just jump
from now
to new-now = (+ (now clock) time)
. Rather, for each scheduled
event within [now; new-now]
the clock is reset to the time of the event
and the event function is executed.
For example, if you have a periodic function scheduled with
(every 1 #(swap! counter inc))
and advance the clock by 5, the counter will be incremented 6 times in total: once initially, as the initial delay is 0 and 5 times for every 1 ms step of the clock.
Advances the mock clock by the specified interval of `time`. Advancing the clock is a continuous action - the clock doesn't just jump from `now` to `new-now = (+ (now clock) time)`. Rather, for each scheduled event within `[now; new-now]` the clock is reset to the time of the event and the event function is executed. For example, if you have a periodic function scheduled with (every 1 #(swap! counter inc)) and advance the clock by 5, the counter will be incremented 6 times in total: once initially, as the initial delay is 0 and 5 times for every 1 ms step of the clock.
(now clock)
Returns the current time for the clock
Returns the current time for the clock
(in interval f)
Schedules no-arg function f
to be invoked in interval
milliseconds. Returns a deferred
representing the returned value of the function (unwrapped if f
itself returns a deferred).
If the returned deferred is completed before the interval has passed, the timeout function
will be cancelled.
Schedules no-arg function `f` to be invoked in `interval` milliseconds. Returns a deferred representing the returned value of the function (unwrapped if `f` itself returns a deferred). If the returned deferred is completed before the interval has passed, the timeout function will be cancelled.
(microseconds n)
Converts microseconds -> milliseconds
Converts microseconds -> milliseconds
(milliseconds n)
Converts milliseconds -> milliseconds
Converts milliseconds -> milliseconds
(minutes n)
Converts minutes -> milliseconds
Converts minutes -> milliseconds
(mock-clock)
(mock-clock initial-time)
Creates a clock designed for testing scheduled behaviors. It can replace the default
scheduler using with-clock
, and can be advanced to a particular time via advance
. By
default, the initial time is 0
.
Creates a clock designed for testing scheduled behaviors. It can replace the default scheduler using `with-clock`, and can be advanced to a particular time via `advance`. By default, the initial time is `0`.
(nanoseconds n)
Converts nanoseconds -> milliseconds
Converts nanoseconds -> milliseconds
(seconds n)
Converts seconds -> milliseconds
Converts seconds -> milliseconds
(with-clock clock & body)
Ensures that all calls to every
and in
are made through the specified clock, rather
than the default one.
Ensures that all calls to `every` and `in` are made through the specified clock, rather than the default one.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close