(defn thunk-timeout [thunk seconds]
(let [task (FutureTask. thunk)
thr (Thread. task)]
(try
(.start thr)
(.get task seconds TimeUnit/MILLISECONDS)
(catch TimeoutException e
(.cancel task true)
(.stop thr (Exception. "Thread stopped!"))
(throw (TimeoutException. "Execution timed out.")))
(catch ExecutionException e
(.cancel task true)
(.stop thr (Exception. "Thread stopped!"))
(throw (SecurityException. "Exception in sandboxed code." (.getCause e))))
(catch Exception e
(.cancel task true)
(.stop thr (Exception. "Thread stopped!"))
(throw (SecurityException. "Exception in sandboxed code." e))))))
Vars in
net.licenser.sandbox/thunk-timeout:
defn
let
Used in 0 other vars
Comments top
No comments for thunk-timeout. Log in to add a comment.