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)
(define control-ch (make-channel)) (actor #:name timer-driver
(thread (lambda () (timer-driver-thread-main control-ch))) #:state [count 0]
(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) (define control-ch (make-channel))
(match e (thread (lambda () (timer-driver-thread-main control-ch)))
[(message (? timer-expired? expiry) 1 #f)
(transition control-ch (send expiry))] (subscribe ($ expiry (timer-expired ? ?))
[(message (? set-timer? instruction) 0 #f) #:meta-level 1
(channel-put control-ch instruction) #:when (positive? count)
#f] (send expiry)
[_ #f])) #: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 (timer-driver-thread-main control-ch)
(define heap (make-timer-heap)) (define heap (make-timer-heap))