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 -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -