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) (struct timer-expired (label msecs) #:prefab)
(define (spawn-timer-driver) (define (spawn-timer-driver)
(actor #:name timer-driver
#:state [count 0]
(define control-ch (make-channel)) (define control-ch (make-channel))
(thread (lambda () (timer-driver-thread-main control-ch))) (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))))
(define (timer-driver e control-ch) (subscribe ($ expiry (timer-expired ? ?))
(match e #:meta-level 1
[(message (? timer-expired? expiry) 1 #f) #:when (positive? count)
(transition control-ch (send expiry))] (send expiry)
[(message (? set-timer? instruction) 0 #f) #:update [count (- count 1)]
#:update-routes) ;; TODO: only update-routes when count is zero
(subscribe ($ instruction (set-timer ? ? ?))
(channel-put control-ch instruction) (channel-put control-ch instruction)
#f] #:update [count (+ count 1)]
[_ #f])) #:update-routes))) ;; TODO: only update-routes when count was zero
(define (timer-driver-thread-main control-ch) (define (timer-driver-thread-main control-ch)
(define heap (make-timer-heap)) (define heap (make-timer-heap))