Hi again,

await-event is not thread-safe.

(defn await-event
  [target event]
  (let [evt       (promise)
        remove-fn (promise)
        handler   (fn [e] (@remove-fn) (deliver evt e))]
    (deliver remove-fn (listen target event handler))
    @evt))

remove-fn should also be a promise. Otherwise the user might click the 
button, after handler registration and before reset of the atom. Then we run 
into a NPE when "calling" nil. Unlikely, but a race condition nevertheless. 
This way the handler would block until the remove function is provided. 
There is also no chance of dead-lock, because the code does nothing else 
than delivering the promise as fast as possible. So the above should work in 
all cases.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to