riemann.time

Clocks and scheduled tasks. Provides functions for getting the current time and running functions (Tasks) at specific times and periods. Includes a threadpool for task execution, controlled by (start!) and (stop!).

after!

(after! delay f)

Calls f after delay seconds

Deferrable

protocol

members

defer

(defer this new-time)

Schedule a task for a new time.

every!

(every! interval f)(every! interval delay f)

Calls f every interval seconds, after delay.

linear-time

linear-time-real

(linear-time-real)

A current time on a linear scale with no fixed epoch; counts in seconds. Unlike unix-time, which can pause, skip, or flow backwards, advances consistently at (close) to wall clock time.

max-task-id

next-tick

(next-tick anchor dt)(next-tick anchor dt now)

Given a period dt, beginning at some point in time anchor, finds the next tick after time now, such that the next tick is separate from anchor by an exact multiple of dt. If now is omitted, defaults to (unix-time).

once!

(once! t f)

Calls f at t seconds.

park-interval

poll-task!

(poll-task!)

Removes the next task from the queue.

reset-tasks!

(reset-tasks!)

Resets the task queue to empty, without triggering side effects.

run-tasks!

(run-tasks! i)

While running, takes tasks from the queue and executes them when ready. Will park the current thread when no tasks are available.

running

schedule!

(schedule! task)

Schedule a task. May awaken a thread from the threadpool to investigate.

schedule-sneaky!

(schedule-sneaky! task)

Schedules a task. Does not awaken any threads.

start!

(start!)

Starts the threadpool to execute tasks on the queue automatically.

stop!

(stop!)

Stops the task threadpool. Waits for threads to exit.

Task

protocol

members

cancel

(cancel task)

Cancel this task.

run

(run task)

Executes this task.

succ

(succ task)

The successive task to this one.

task-id

(task-id)

Return a new task ID.

tasks

Scheduled operations.

thread-count

threadpool

unix-time

unix-time-real

(unix-time-real)

The current unix epoch time in seconds, taken from System/currentTimeMillis.