Skip to content

Instantly share code, notes, and snippets.

@Raynes
Created March 19, 2010 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynes/337804 to your computer and use it in GitHub Desktop.
Save Raynes/337804 to your computer and use it in GitHub Desktop.
(defn thunk-timeout [thunk seconds]
(let [task (FutureTask. thunk)
thr (Thread. task)]
(try
(.start thr)
(.get task seconds TimeUnit/SECONDS)
(catch TimeoutException e
(.cancel task true)
(.stop thr (Exception. "Thread stopped!")) "Execution Timed Out"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment