allow / check for :quit action to stop a background service (task)

This commit is contained in:
Helmut Merz 2025-02-15 16:57:53 +01:00
parent c90d953f2b
commit 0da989d73a

View file

@ -84,7 +84,7 @@
(defgeneric do-listen (ctx)
(:method ((ctx service))
(do ((r (do-step ctx) (do-step ctx)))
((not r)))))
((eql r '(:quit))))))
(defgeneric do-step (ctx)
(:method ((ctx service))
@ -120,7 +120,6 @@
(progn
(setup-services cfg)
(do-listen *root*))
;(lpq:pop-queue *quit-queue*))
(shutdown)))
(defun add-action (ctx pat hdlr)
@ -138,22 +137,17 @@
(dolist (a (config:actions cfg))
(add-action child (car a) (cadr a)))
(setf (gethash (config:name cfg) services) child)
(do-start child)
))))
(do-start child)))))
(defgeneric handle-message (ctx msg)
(:method ((ctx base-context) msg)
(cond
((do-actions ctx msg) t)
(t (util:lgw "no action selected" msg)))))
(do-actions ctx msg)))
(defun do-actions (ctx msg &optional (acts #'actions))
(let ((hdlrs (select msg (funcall acts ctx))))
(when hdlrs
(dolist (hdlr hdlrs)
(funcall hdlr ctx msg))
t)))
(if hdlrs
(mapcar #'(lambda (hdlr) (funcall hdlr ctx msg)) hdlrs)
(util:lgw "no action selected" msg))))
;;;; some simple predefined actions