Clojure - shutdown-agents 函数

此函数用于关闭任何正在运行的代理。

语法

语法如下。

(shutdown-agents)

参数 − None.

返回值 − None.

示例

以下程序显示了如何使用它的示例。

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def counter (agent 0))
   (println @counter)
   
   (send counter + 100)
   (println "Incrementing Counter")
   (println @counter)
   (shutdown-agents))
(Example)

输出

上面的程序产生以下输出。

0
Incrementing Counter
0

上述程序的主要区别在于,该程序现在将终止,因为所有代理都将正确关闭。

❮ clojure_agents