-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker.scm
27 lines (23 loc) · 845 Bytes
/
ticker.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;;; ticker.scm
;;; Propagoi tick! -signaalia kaikille sitä pyytäneille olioille pyyntöjärjestyksessä.
(define (new-ticker)
(let ((target-objects '()))
; Metodit
(define (tick!)
(for-each (lambda (object)
((object 'tick!)))
target-objects))
(define (request-ticking! object)
(set! target-objects
(append target-objects
(list object))))
(define (stop-ticking-me! object)
(set! target-objects
(remove-from-list target-objects object)))
; Dispatch
(define (dispatch method)
(cond ((eq? method 'tick!) tick!)
((eq? method 'request-ticking!) request-ticking!)
((eq? method 'stop-ticking-me!) stop-ticking-me!)
(else (error "Unknown method! ticker." method))))
dispatch))