取消引用一个已交付的承诺,如果调用线程被中断,将会抛出InterruptedException
(let [p (promise)]
(deliver p :value)
(.interrupt (Thread/currentThread))
(assert (realized? p))
(deref p)) ;; => InterruptedException
这很意外,因为检索已实现承诺的值不应该阻塞。
通过Promesa库使用CompletableFuture
不会抛出问题
(require '[promesa.core :as p]) ;'
(let [p (p/deferred)]
(p/resolve! p :value)
(.interrupt (Thread/currentThread))
(deref p)) ;; => ::value