|
26 | 26 | (defstruct dispatcher
|
27 | 27 | (name nil :type (or nil symbol keyword))
|
28 | 28 | (workers nil :type list)
|
| 29 | + (openp t :type boolean) |
29 | 30 | (lock (bt2:make-lock) :type bt2:lock))
|
30 | 31 |
|
31 | 32 | (defgeneric resolve-actor (actor)
|
32 | 33 | (:method ((actor dispatcher))
|
33 |
| - (reduce #'min |
34 |
| - (dispatcher-workers actor) |
35 |
| - :initial-value -1 |
36 |
| - :key (lambda (actor) (q:qsize (actor-queue actor))))) |
| 34 | + (a:extremum (dispatcher-workers actor) |
| 35 | + #'< |
| 36 | + :key (lambda (actor) (q:qsize (actor-queue actor))))) |
37 | 37 | (:method ((actor symbol))
|
38 | 38 | (gethash actor *registry*)))
|
39 | 39 |
|
|
70 | 70 | (:method ((actor actor))
|
71 | 71 | (send-signal actor (make-close-signal))
|
72 | 72 | (setf (actor-openp actor) nil))
|
| 73 | + (:method ((actor dispatcher)) |
| 74 | + (remhash (dispatcher-name actor) *registry*) |
| 75 | + (dolist (worker (dispatcher-workers actor)) |
| 76 | + (close-actor worker)) |
| 77 | + (setf (dispatcher-openp actor) nil)) |
73 | 78 | (:method ((actor t))
|
74 | 79 | (close-actor (resolve-actor actor))))
|
75 | 80 |
|
|
78 | 83 | (:method ((actor actor))
|
79 | 84 | (bt2:join-thread (actor-thread actor))
|
80 | 85 | (apply #'values (actor-store actor)))
|
| 86 | + (:method ((actor dispatcher)) |
| 87 | + (mapcar #'join-actor (dispatcher-workers actor))) |
81 | 88 | (:method ((actor t))
|
82 | 89 | (join-actor (resolve-actor actor))))
|
83 | 90 |
|
|
86 | 93 | (:method ((actor actor))
|
87 | 94 | (remhash (actor-name actor) *registry*)
|
88 | 95 | (bt2:destroy-thread (actor-thread actor)))
|
| 96 | + (:method ((actor dispatcher)) |
| 97 | + (remhash (dispatcher-name actor) *registry*) |
| 98 | + (mapcar #'destroy-actor (dispatcher-workers actor))) |
89 | 99 | (:method ((actor t))
|
90 | 100 | (destroy-actor (resolve-actor actor))))
|
91 | 101 |
|
92 | 102 | (defun close-and-join-actors (&rest actors)
|
93 | 103 | (mapc #'close-actor actors)
|
94 |
| - (mapc #'join-actor actors)) |
| 104 | + (mapcar #'join-actor actors)) |
95 | 105 |
|
96 | 106 | (defgeneric send (actor &rest args)
|
97 | 107 | (:documentation "Asyncronously send a message to an actor.")
|
|
0 commit comments