diff --git a/scopes-core.asd b/scopes-core.asd index 359aa7c..39a0e65 100644 --- a/scopes-core.asd +++ b/scopes-core.asd @@ -18,6 +18,7 @@ (:file "logging" :depends-on ("config" "util/util")) (:file "shape/shape") (:file "util/util") + (:file "util/async" :depends-on ("util/util")) (:file "util/crypt" :depends-on ("util/util")) (:file "util/iter") (:file "testing" :depends-on ("util/util"))) diff --git a/test/test-core.lisp b/test/test-core.lisp index a1e1d08..ff3bfa0 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -3,6 +3,7 @@ (defpackage :scopes/test-core (:use :common-lisp) (:local-nicknames (:alx :alexandria) + (:async :scopes/util/async) (:config :scopes/config) (:core :scopes/core) (:crypt :scopes/util/crypt) @@ -56,6 +57,7 @@ (unwind-protect (progn (test-util) + (test-util-async) (test-util-crypt) (test-util-iter) (test-shape) @@ -82,6 +84,10 @@ (== (util:plist-add pl :b 1) '(:b 1 :a 0)) (== pl '(:b 1 :a 0)))) +(deftest test-util-async () + (let ((tsk (async:task))) + (format t "~%~a~%" (async::taskid tsk)))) + (deftest test-util-crypt () (util:lgi (crypt:create-secret)) ) diff --git a/util/async.lisp b/util/async.lisp new file mode 100644 index 0000000..891c64d --- /dev/null +++ b/util/async.lisp @@ -0,0 +1,29 @@ +;;;; cl-scopes/util/async - utilities for asynchronous (concurrent or parallel) operations + +(defpackage :scopes/util/async + (:use :common-lisp) + (:local-nicknames (:util :scopes/util) + (:lp :lparallel) + (:lpq :lparallel.queue)) + (:export #:startup #:shutdown + #:task #:start #:restart #:stop #:kill #:status + #:mailbox #:send #:receive)) + +(in-package :scopes/util/async) + +(when (not (boundp '+quit-message+)) + (defconstant +quit-message+ (gensym "QUIT"))) + +(when (null lp:*kernel*) + (setf lp:*kernel* (lp:make-kernel 2))) + +(defclass task () + ((job :reader job :initarg :job) + (taskid :reader taskid :initform (gensym "TSK")) + (channel :reader channel :initform (lp:make-channel)) + (mailbox :reader mailbox :initarg :mailbox :initform nil) + (status :accessor status :initform :new) + (logdata :accessor logdata :initform nil))) + +(defun task () + (make-instance 'task))