代理呼叫代理

时间:2011-11-10 19:14:33

标签: clojure

我正试图围绕代理商呼叫代理商时发生的事情。

(def top (agent 0))
(def bottom (agent 1))

我有一对最小的一对:

(defn testA []
  "This returns 'top', whose value is 'bottom', whose value is 2."
  (send top (fn [top-value]
          (send bottom inc)))
  (await top)
  top)

(defn testB []
  "This never terminates."
  (send top (fn [top-value]
          (send bottom inc)
          (await bottom) ;;<- this is new
          bottom))
  (await top)
  top)

内心等待发生了什么?当一个代理人打电话给另一个时,有什么因素可以发挥作用?

谢谢,

1 个答案:

答案 0 :(得分:2)

简短的回答是,您无法在座席操作中使用await。您可以使用(agent-error top)

查看错误(如果您从当前等待中断)

对于更长的答案(解释为什么你不能这样做),你将不得不(a)等待一些clojure大师:)我的看法是,你可以引入死锁或其他一些灾难。

另请注意,使用topbottom会返回代理本身,而不是其值。要获得该值,您需要(deref top)@top

相关问题