thunk-timeout

net.licenser.sandbox

  • (thunk-timeout thunk seconds)

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source net/licenser/sandbox.clj:38 top

(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.