Skip to content
Browse files

Make thunk-timeout's threadgroup behavior optional.

  • Loading branch information...
1 parent 0cd61a4 commit c3133795942dc37c65006565ff5a73295b55b5dc @Raynes Raynes committed Oct 24, 2011
Showing with 7 additions and 6 deletions.
  1. +1 −1 project.clj
  2. +6 −5 src/clojail/core.clj
View
2 project.clj
@@ -1,3 +1,3 @@
-(defproject clojail "0.4.4"
+(defproject clojail "0.4.5"
:description "An experimental sandboxing library."
:dependencies [[clojure "1.3.0"]])
View
11 src/clojail/core.clj
@@ -39,9 +39,10 @@
([thunk time unit]
(thunk-timeout thunk time unit identity))
([thunk time unit transform]
- (let [tg (ThreadGroup. "sandbox")
- task (FutureTask. (comp transform thunk))
- thr (Thread. tg task)]
+ (thunk-timeout thunk time unit identity nil))
+ ([thunk time unit transform tg]
+ (let [task (FutureTask. (comp transform thunk))
+ thr (if tg (Thread. tg task) (Thread. task))]
(try
(.start thr)
(.get task time (or (uglify-time-unit unit) unit))
@@ -53,7 +54,7 @@
(.cancel task true)
(.stop thr)
(throw e))
- (finally (.stop tg))))))
+ (finally (when tg (.stop tg)))))))
(defn- separate [s]
(set
@@ -179,7 +180,7 @@
~init
~(ensafen code))]
(with-bindings bindings (jvm-sandbox #(eval code) context)))))
- timeout :ms transform)))))
+ timeout :ms transform (ThreadGroup. "sandbox"))))))
(defn sandbox
"Convenience wrapper function around sandbox* to create a sandbox function out of a tester.

0 comments on commit c313379

Please sign in to comment.
Something went wrong with that request. Please try again.