Skip to content

Instantly share code, notes, and snippets.

@LauJensen
Created October 14, 2010 10:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LauJensen/626002 to your computer and use it in GitHub Desktop.
Save LauJensen/626002 to your computer and use it in GitHub Desktop.
(defn with-timeout [thunk]
(let [task (FutureTask. thunk)
thr (Thread. task)]
(try
(.start thr)
(.get task 10 TimeUnit/SECONDS)
(catch TimeoutException e
(.cancel task true)
(.stop thr (Exception. e))
nil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment