Capture the current value of the specified vars and rebind
them on the agent thread before executing the action.
Example:
(capture-and-send [*out*] a f b c)
(defmacro capture-and-send
"Capture the current value of the specified vars and rebind
them on the agent thread before executing the action.
Example:
(capture-and-send [*out*] a f b c)"
[vars agent action & args]
(let [locals (map #(gensym (name %)) vars)]
`(let [~@(interleave locals vars)
action# (fn [& args#]
(binding [~@(interleave vars locals)]
(apply ~action args#)))]
(send ~agent action# ~@args))))
Comments top
No comments for capture-and-send. Log in to add a comment.