Skip to content

Instantly share code, notes, and snippets.

@weavejester
Created May 19, 2012 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save weavejester/2732467 to your computer and use it in GitHub Desktop.
Save weavejester/2732467 to your computer and use it in GitHub Desktop.
(defn watch-until [reference pred timeout-ms]
(let [result (promise)
watch-key (random-uuid)]
(try
(add-watch reference
watch-key
(fn [_ _ _ value]
(when (pred value)
(deliver result true))))
(or (pred @reference)
(deref result timeout-ms false))
(finally
(remove-watch reference watch-key)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment