Actorize the timer driver and avoid inertness-preventing permanent subscription at ground-meta-level

This commit is contained in:
Tony Garnock-Jones 2014-06-23 07:28:20 -04:00
parent bfe9a5224d
commit 7502656531
1 changed files with 16 additions and 14 deletions

View File

@ -20,21 +20,23 @@
(struct timer-expired (label msecs) #:prefab)
(define (spawn-timer-driver)
(define control-ch (make-channel))
(thread (lambda () (timer-driver-thread-main control-ch)))
(spawn timer-driver control-ch (gestalt-union (sub (set-timer ? ? 'relative))
(sub (set-timer ? ? 'absolute))
(pub (timer-expired ? ?))
(sub (timer-expired ? ?) #:meta-level 1))))
(actor #:name timer-driver
#:state [count 0]
(define (timer-driver e control-ch)
(match e
[(message (? timer-expired? expiry) 1 #f)
(transition control-ch (send expiry))]
[(message (? set-timer? instruction) 0 #f)
(channel-put control-ch instruction)
#f]
[_ #f]))
(define control-ch (make-channel))
(thread (lambda () (timer-driver-thread-main control-ch)))
(subscribe ($ expiry (timer-expired ? ?))
#:meta-level 1
#:when (positive? count)
(send expiry)
#:update [count (- count 1)]
#:update-routes) ;; TODO: only update-routes when count is zero
(subscribe ($ instruction (set-timer ? ? ?))
(channel-put control-ch instruction)
#:update [count (+ count 1)]
#:update-routes))) ;; TODO: only update-routes when count was zero
(define (timer-driver-thread-main control-ch)
(define heap (make-timer-heap))