https://github.com/fukamachi/legion.git
git clone 'https://github.com/fukamachi/legion.git'
(ql:quickload :legion)
Jesus asked him, “What is your name?” And he said, “My name is Legion, for we are many.” ── Gospel of Mark chapter 5, verse 9
(defparameter *worker*
(make-worker
(let ((out *standard-output*))
(lambda (worker)
(multiple-value-bind (val existsp)
(next-job worker)
(format out "Processed: ~S~%" val))))))
(start-worker *worker*)
(add-job *worker* 10)
(add-job *worker* "Hi")
(stop-worker *worker*)
(defparameter *cluster*
(make-cluster 4
(let ((out *standard-output*))
(lambda (worker)
(multiple-value-bind (val existsp)
(next-job worker)
(format out "Processed: ~S~%" val))))))
(start-cluster *cluster*)
(add-job *cluster* 10)
(add-job *cluster* "Hi")
(stop-cluster *cluster*)
NOTE: Cluster doesn't guarantee the order of processing jobs.
Base structure class of workers.
Create and return a worker thread which has a fixed-length queue. process-fn is a funcallable object which takes a single value.
You can specify the value by specifying :queue-size. The default value is 128.
Return the worker's status which is specifically one of :running, :idle, :shutting and :shutdown.
Return the number of outstanding jobs of the worker.
Start the given worker to process jobs.
Stop the given worker after processing its queued jobs.
Stop the given worker immediately (outstanding jobs will be remained in its queue).
Enqueue a new job val which will be passed to a function specified for make-worker.
Dequeue a job from worker's queue.
Base structure class of clusters.
Create and return a cluster with worker-num workers with process-fn.
You can specify a scheduler function which takes exact 2 arguments – workers and a job – for task-scheduling. The default is round-robin scheduler.
Return the cluster's status which is one of :running, :shutting and :shutdown.
Start workers of cluster.
Return workers of cluster in simple-array.
Copyright (c) 2015 Eitaro Fukamachi (e.arrows@gmail.com)
Licensed under the BSD 2-Clause License.