summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/scripting/agenda.scm24
-rw-r--r--doc/api.texi12
2 files changed, 35 insertions, 1 deletions
diff --git a/chickadee/scripting/agenda.scm b/chickadee/scripting/agenda.scm
index c815afa..f16dc45 100644
--- a/chickadee/scripting/agenda.scm
+++ b/chickadee/scripting/agenda.scm
@@ -28,8 +28,10 @@
clear-agenda
schedule-at
schedule-after
+ schedule-every
at
- after))
+ after
+ every))
(define-record-type <agenda>
(%make-agenda time queue)
@@ -93,8 +95,28 @@
"Schedule THUNK to be run after DELAY."
(schedule (current-agenda) (+ (agenda-time) delay) thunk))
+(define* (schedule-every interval thunk #:optional n)
+ "Schedule THUNK to run every INTERVAL amount of time. Repeat this N
+times, or indefinitely if not specified."
+ (schedule-after interval
+ (lambda ()
+ (cond
+ ((not n)
+ (thunk)
+ (schedule-every interval thunk))
+ ((> n 0)
+ (thunk)
+ (schedule-every interval thunk (- n 1)))))))
+
(define-syntax-rule (at time body ...)
(schedule-at time (lambda () body ...)))
(define-syntax-rule (after delay body ...)
(schedule-after delay (lambda () body ...)))
+
+(define-syntax every
+ (syntax-rules ()
+ ((_ (interval n) body ...)
+ (schedule-every interval (lambda () body ...) n))
+ ((_ interval body ...)
+ (schedule-every interval (lambda () body ...)))))
diff --git a/doc/api.texi b/doc/api.texi
index e1f6acc..1a56039 100644
--- a/doc/api.texi
+++ b/doc/api.texi
@@ -955,6 +955,12 @@ Schedule @var{thunk}, a procedure of zero arguments, to be run after
@var{delay}.
@end deffn
+@deffn {Scheme Procedure} schedule-every @var{interval} @var{thunk} [@var{n}]
+Schedule @var{thunk}, a procedure of zero arguments, to be run every
+@var{interval} amount of time. Repeat this @var{n} times, or
+indefinitely if not specified.
+@end deffn
+
@deffn {Scheme Syntax} at @var{time} @var{body} @dots{}
Schedule @var{body} to be evaluated at @var{time}.
@end deffn
@@ -963,6 +969,12 @@ Schedule @var{body} to be evaluated at @var{time}.
Schedule @var{body} to be evaluated after @var{delay}.
@end deffn
+@deffn {Scheme Syntax} every @var{interval} @var{body} @dots{}
+@deffnx {Scheme Syntax} every (@var{interval} @var{n}) @var{body} @dots{}
+Schedule @var{body} to be evaluated every @var{interval} amount of
+time. Repeat this @var{n} times, or indefinitely if not specified.
+@end deffn
+
@node Coroutines
@subsection Coroutines