#lang imperative-syndicate

(require/activate imperative-syndicate/drivers/timer)

(spawn #:name 'plain-timer-demo
       (field [count 0])
       (on-start (send! (set-timer 'main-timer 0 'relative)))
       (on (message (timer-expired 'main-timer $now))
           (log-info "main-timer expired at ~a" now)
           (count (+ (count) 1))
           (when (< (count) 5)
             (send! (set-timer 'main-timer 500 'relative)))))

(spawn #:name 'later-than-demo
       (field [deadline (current-inexact-milliseconds)]
              [count 0])
       (on (asserted (later-than (deadline)))
           (log-info "later-than ticked for deadline ~a" (deadline))
           (count (+ (count) 1))
           (when (< (count) 5)
             (deadline (+ (deadline) 500)))))
