How do Clojure futures and promises differ?

后端 未结 5 1790
感情败类
感情败类 2020-12-22 22:12

Both futures and promises block until they have calculated their values, so what is the difference between them?

5条回答
  •  长情又很酷
    2020-12-22 22:47

    There are already excellent answers so only adding the "how to use" summary:

    Both

    Creating promise or future returns a reference immediately. This reference blocks on @/deref until result of computation is provided by other thread.

    Future

    When creating future you provide a synchronous job to be done. It's executed in a thread from the dedicated unbounded pool.

    Promise

    You give no arguments when creating promise. The reference should be passed to other 'user' thread that will deliver the result.

提交回复
热议问题