fix async stuff: kernels, interrupt handlinng
This commit is contained in:
parent
e7178b20d9
commit
5c2126805d
4 changed files with 34 additions and 20 deletions
|
@ -79,8 +79,8 @@
|
|||
(async:start (task ctx)))
|
||||
(:method ((ctx root-service))
|
||||
(setf (task ctx)
|
||||
(async:make-task :cls 'async:async-task :handle-message #'handle-message))
|
||||
(async:start (task ctx :blocking t))))
|
||||
(async:make-task :cls 'async:task :handle-message #'handle-message))
|
||||
(async:start (task ctx))))
|
||||
|
||||
(defgeneric send (rcvr msg)
|
||||
(:method ((rcvr base-context) msg)
|
||||
|
@ -97,15 +97,17 @@
|
|||
(gethash name services))))
|
||||
|
||||
(defun setup-services (&optional (cfg config:*root*))
|
||||
(async:init)
|
||||
(setf *root* (make-instance 'root-service :config cfg))
|
||||
(dolist (c (reverse (config:children cfg)))
|
||||
(add-service *root* c)))
|
||||
|
||||
(defun shutdown ()
|
||||
(if (task *root*)
|
||||
(async:stop (task *root*)))
|
||||
(dolist (ctx (alx:hash-table-values (services *root*)))
|
||||
(funcall (config:shutdown (config ctx)) ctx)))
|
||||
(funcall (config:shutdown (config ctx)) ctx))
|
||||
(if (and (task *root*))
|
||||
(async:stop (task *root*)))
|
||||
(async:finish))
|
||||
|
||||
(defun run-services (&optional (cfg config:*root*))
|
||||
(unwind-protect
|
||||
|
|
|
@ -44,7 +44,9 @@
|
|||
(== (shape:head-value pr1 :name) :admin)))
|
||||
|
||||
(deftest test-client (client)
|
||||
(let ((msg (message:create
|
||||
'(:auth :login)
|
||||
:data '(:org "system" :name "admin" :password "sc0pes"))))
|
||||
(client:send-message client msg)))
|
||||
(let (msg rsp)
|
||||
(setf msg (message:create '(:auth :login)
|
||||
:data '(:org "system" :name "admin" :password "sc0pes")))
|
||||
(setf rsp (client:send-message client msg))
|
||||
(print rsp)
|
||||
))
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
(== pl '(:b 1 :a 0))))
|
||||
|
||||
(deftest test-util-async ()
|
||||
(async:init)
|
||||
(let ((tsk (async:make-task)))
|
||||
(== (async:status tsk) :new)
|
||||
(async:start tsk)
|
||||
|
@ -98,8 +99,8 @@
|
|||
(== (async:status tsk) :running)
|
||||
(async:send tsk :hello)
|
||||
(== (async:stop tsk) '(:hello))
|
||||
(== (async:status tsk) :done)
|
||||
))
|
||||
(== (async:status tsk) :done) )
|
||||
(async:finish))
|
||||
|
||||
(deftest test-util-crypt ()
|
||||
(let ((s1 (crypt:create-secret))
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
(:local-nicknames (:util :scopes/util)
|
||||
(:lp :lparallel)
|
||||
(:lpq :lparallel.queue))
|
||||
(:export #:task #:async-task
|
||||
(:export #:init #:finish #:task #:async-task
|
||||
#:make-task #:start #:stop #:status #:data #:send))
|
||||
|
||||
(in-package :scopes/util/async)
|
||||
|
@ -15,9 +15,15 @@
|
|||
(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
(progn
|
||||
(when (not (boundp '+quit-message+))
|
||||
(defconstant +quit-message+ (gensym "QUIT")))
|
||||
(when (null lp:*kernel*)
|
||||
(setf lp:*kernel* (lp:make-kernel (serapeum:count-cpus))))))
|
||||
(defconstant +quit-message+ (gensym "QUIT")))))
|
||||
|
||||
(defun init ()
|
||||
(when (null lp:*kernel*)
|
||||
(setf lp:*kernel* (lp:make-kernel (serapeum:count-cpus)))))
|
||||
|
||||
(defun finish ()
|
||||
(when lp:*kernel*
|
||||
(lp:end-kernel)))
|
||||
|
||||
(defun noop (&rest params))
|
||||
|
||||
|
@ -27,12 +33,15 @@
|
|||
(progn
|
||||
(funcall startup tsk)
|
||||
(when mb
|
||||
(loop for msg = (lpq:pop-queue mb)
|
||||
(handler-case
|
||||
(loop for msg = (lpq:pop-queue mb)
|
||||
until (eq msg +quit-message+)
|
||||
do (funcall handle-message tsk msg)))
|
||||
(funcall teardown tsk)
|
||||
(data tsk))
|
||||
(setf (status tsk) :done))))
|
||||
do (funcall handle-message tsk msg))
|
||||
(sb-sys:interactive-interrupt (e)
|
||||
(format t "~&async:standard-job: ~a~%" e)))))
|
||||
(setf (status tsk) :done)
|
||||
(funcall teardown tsk)
|
||||
(data tsk))))
|
||||
|
||||
;;;; task class and related functions / methods
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue