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

c# - Move local mssql database to webhosted MYSQL -

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -