From 7e1bfd9f484cc9b574ea160ca964208a48bb3849 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 19 Feb 2025 17:50:18 +0100 Subject: [PATCH] core/async: + test (and fixes) for working with mailbox / handle-message --- test/test-core.lisp | 12 ++++++++++-- util/async.lisp | 10 +++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/test-core.lisp b/test/test-core.lisp index 87d2860..5aa1c7a 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -90,8 +90,16 @@ (async:start tsk) (== (async:status tsk) :running) (async:stop tsk) - ;(sleep 0.1) - (== (async:status tsk) :done))) + (== (async:status tsk) :done)) + (let ((tsk (async:make-task :handle-message + #'(lambda (tsk msg) (push msg (async:data tsk)))))) + (== (async:status tsk) :new) + (async:start tsk) + (== (async:status tsk) :running) + (async:send tsk :hello) + (== (async:stop tsk) '(:hello)) + (== (async:status tsk) :done) + )) (deftest test-util-crypt () (let ((s1 (crypt:create-secret)) diff --git a/util/async.lisp b/util/async.lisp index 8b74448..c77ff9f 100644 --- a/util/async.lisp +++ b/util/async.lisp @@ -5,8 +5,7 @@ (:local-nicknames (:util :scopes/util) (:lp :lparallel) (:lpq :lparallel.queue)) - (:export #:task #:make-task #:start #:stop #:status #:logdata - #:mailbox #:send)) + (:export #:task #:make-task #:start #:stop #:status #:data #:send)) (in-package :scopes/util/async) @@ -30,9 +29,10 @@ (loop for msg = (lpq:pop-queue mb) until (eq msg +quit-message+) do (funcall handle-message tsk msg))) - (funcall teardown tsk)) + (funcall teardown tsk) + (data tsk)) (setf (status tsk) :done) - (logdata tsk)))) + ))) ;;;; task class and related functions / methods @@ -42,7 +42,7 @@ (channel :reader channel :initform (lp:make-channel)) (mailbox :accessor mailbox :initform nil) (status :accessor status :initform :new) - (logdata :accessor logdata :initform nil))) + (data :accessor data :initform nil))) (defun make-task (&key (startup #'noop) (teardown #'noop) handle-message) (let ((tsk (make-instance 'task)))