summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/signals.texi5
-rw-r--r--sly/signal.scm7
2 files changed, 11 insertions, 1 deletions
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."