29 lines
942 B
Common Lisp
29 lines
942 B
Common Lisp
;;;; 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))
|