Is there a way to be notified when a clojure future finishes?

前端 未结 5 1467
鱼传尺愫
鱼传尺愫 2021-02-04 14:56

Is there a way to set a watch on a future so that it triggers a callback when it is done?

something like this?

> (def a (future (Thread/sleep 1000) \"         


        
5条回答
  •  独厮守ぢ
    2021-02-04 15:07

    Instead of adding additional time with Thread/Sleep , I'm leveraging on the fact that @future-ref for any reference to the future will wait until the future is done.

    (defn  wait-for
      [futures-to-complete]
      (every? #(@%) futures-to-complete))
    

提交回复
热议问题