From 8ac70ff3cef2963c460ce5382e37946eb0a4914e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 9 Mar 2015 08:46:43 -0400 Subject: signals: Add signal-timer. * sly/signal.scm (signal-timer): New procedure. * doc/api/signals.texi: Document it. --- doc/api/signals.texi | 5 +++++ sly/signal.scm | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/api/signals.texi b/doc/api/signals.texi index a4e2c01..9f674e1 100644 --- a/doc/api/signals.texi +++ b/doc/api/signals.texi @@ -191,6 +191,11 @@ Create a new signal that takes on the value of @var{signal} every Create a new signal that emits @var{step} every @var{step} ticks. @end deffn +@deffn {Scheme Procedure} signal-timer [@var{step}] +Create a new signal that emits the total time elapsed since its +creation every @var{step} (1 by default) ticks. +@end deffn + @deffn {Scheme Procedure} signal-since @var{step} @var{signal} Create a new signal that emits the time since @var{signal} was updated ever @var{step} ticks. diff --git a/sly/signal.scm b/sly/signal.scm index 788bb25..83f1ea5 100644 --- a/sly/signal.scm +++ b/sly/signal.scm @@ -50,7 +50,7 @@ signal-tap signal-timestamp signal-time signal-sample - signal-every signal-since + signal-every signal-timer signal-since signal-delay signal-throttle signal-generator)) @@ -366,6 +366,11 @@ ticks." "Create a new signal that emits STEP every STEP ticks." (signal-sample step (make-signal step))) +(define* (signal-timer #:optional (step 1)) + "Create a new signal that emits the total time elapsed since its +creation every STEP ticks." + (signal-fold + 0 (signal-every step))) + (define (signal-since step signal) "Create a new signal that emits the time since SIGNAL was updated every STEP ticks." -- cgit v1.2.3