clojure - Executing a function with a timeout -



clojure - Executing a function with a timeout -

what idiomatic way of executing function within time limit? like,

(with-timeout 5000 (do-somthing))

unless do-something returns within 5000 throw exception or homecoming nil.

edit: before points out there is,

clojure (with-timeout ... macro)

but future keeps executing not work in case.

this isn't can 100% reliably on jvm. way stop after while give new thread, , send thread exception when want stop. code can grab exception, or can spin thread don't control, or...

but of time, , if command code that's beingness timed out, can in clojail:

if wanted create prettier define macro like

(defmacro with-timeout [time & body] `(thunk-timeout (fn [] ~@body) ~time))

clojure

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -