Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Clojure by
retagged by

Dereferencing a delivered promise will throw an InterruptedException when the calling thread is interrupted:

(let [p (promise)]
  (deliver p :value)
  (.interrupt (Thread/currentThread))
  (assert (realized? p))
  (deref p)) ;; => InterruptedException

This is unexpected, as retrieving the value of a realized promise should not block.

Using CompletableFuture through the Promesa library does not throw:

(require '[promesa.core :as p]) ;'

(let [p (p/deferred)]
  (p/resolve! p :value)
  (.interrupt (Thread/currentThread))
  (deref p)) ;; => ::value

2 Answers

0 votes
by

This is Clojure or ClojureScript or both?

by
Clojure -- there are no threads in ClojureScript
0 votes
by
...