Created
March 10, 2010 11:51
-
-
Save zahardzhan/327795 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [precedence-counter (atom 0)] | |
(defn make-agent | |
{:post [(instance? clojure.lang.Agent %)]} | |
[& state] | |
(let [state (apply array-map state) | |
agent-type (or (:type state) ::agent) | |
state (dissoc state :type) | |
a (agent (with-meta | |
(merge {:name nil | |
:state :created | |
:alive true | |
:fail false | |
:tag nil | |
:lock (atom false) | |
:program (constantly false) | |
:precedence (swap! precedence-counter inc)} | |
state) | |
{:type agent-type}))] | |
(send a assoc | |
:this (delay a) | |
:env (ref (delay {:agents (set-sorted-by-precedence a)}))) | |
(await a) | |
a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment