30 lines
861 B
Common Lisp
30 lines
861 B
Common Lisp
;;;; cl-scopes/core/actor - basic actor definitions
|
|
|
|
(defpackage :scopes/core/actor-ng
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:async :scopes/util/async)
|
|
(:util :scopes/util))
|
|
(:export #:ac-loop #:become #:create #:send
|
|
#:message #:content #:customer
|
|
#:*logger* #:*root*
|
|
#:echo #:inc #:lgi
|
|
#:calculator #:plus #:minus #:show #:send-value))
|
|
|
|
(in-package :scopes/core/actor-ng)
|
|
|
|
;;;; virtual actor - async:task + behavior
|
|
|
|
(eval-when (:compile-toplevel :load-toplevel :execute)
|
|
(when (not (boundp '+quit-message+))
|
|
(defconstant +quit-message+ (gensym "QUIT"))))
|
|
|
|
(defun ac-loop (tsk bhv)
|
|
(let ((next (ac-step tsk bhv)))
|
|
(unless (eq next +quit-message+)
|
|
(ac-loop tsk (or next bhv)))))
|
|
|
|
(defun ac-step (tsk bhv)
|
|
(let ((msg (async:receive tsk)))
|
|
(funcall bhv tsk msg)))
|
|
|
|
|