racket-timers
If you find that this library lacks some feature you need, or you have a suggestion for improving it, please don’t hesitate to get in touch with me!
1 Introduction
This library provides utilities for managing a heap of timeouts when programming in an event-driven style with sync.
2 What to require
All the functionality below can be accessed with a single require:
(require (planet tonyg/timers:1:=0)) |
2.1 Raw timeout events
2.2 Timers and timer managers
procedure
procedure
(add-absolute-timer! tm deadline handler) → pending-timer?
tm : timer-manager? deadline : nonnegative-number? handler : (-> any?)
procedure
(add-relative-timer! tm delta-msec handler) → pending-timer?
tm : timer-manager? delta-msec : number? handler : (-> any?)
procedure
(fire-single-timer-evt tm k-fired k-not-fired) → evt? tm : timer-manager? k-fired : (->* () #:rest any? any?) k-not-fired : (-> any?)
procedure
(fire-single-timer tm k-fired k-not-fired) → any?
tm : timer-manager? k-fired : (->* () #:rest any? any?) k-not-fired : (-> any?)
procedure
(fire-timers-evt tm) → evt?
tm : timer-manager?
procedure
(fire-timers tm) → void?
tm : timer-manager?
procedure
(cancel-timer! t) → void?
t : pending-timer?
struct
(struct timer-manager (heap) #:extra-constructor-name make-timer-manager #:transparent) heap : heap?
struct
(struct pending-timer (deadline handler cancelled?) #:extra-constructor-name make-pending-timer #:transparent) deadline : nonnegative-number? handler : (-> any?) cancelled? : boolean?
pending-timer-deadline is the value of current-inexact-milliseconds after which the event will fire (when the pending timer’s timer-manager is checked for expired events).
pending-timer-handler is the timer callback. It will be called with no arguments, and may yield any number of values. The values are ignored if either fire-timers or fire-timers-evt is used to trigger the firing of the timer, and are used if either fire-single-timer or fire-single-timer-evt fire the timer.
pending-timer-cancelled? indicates whether this timer has been cancelled. A cancelled timer’s callback will never be called; it is as if it were never registered.
procedure
(timer-manager-idle? tm) → boolean?
tm : timer-manager?