Timer facility

schedule-task

schedules body for invocation after given time and returns a
CancelableFutureTask. (cancel task) will cancel the task if possible and
return true iff cancellation was successful.

(let[task(timer/schedule-task1000(println"This will print in 1000ms if not canceled"))](Thread/sleep(rand-nth[1100900]))(if(timer/canceltask)(println"Task was cancelled")(println"Task already executed")))

with-timeout

schedules timeout-form for invocation after given timeout and wraps named
fn so that calling it with any arguments also cancels the timeout if possible.
If the timeout has already been invoked, the fn will not run and will
immediately return nil

(with-timeoutprintln800(println"Timeout task triggered")(Thread/sleep(rand-nth[900700]))(println"Timeout task was cancelled"))(defnhandler[req](with-channelreqchannel(with-timeoutsend!1000(send!{:status200:body"service did not return in 1000ms"})(let[result(call-a-long-running-service)];; Call `send!` cancels the timeout if possible.;; If the timeout has already been invoked (the service takes more than 1000ms to return),;; `send!` will not run and return nil immediately.(send!{:status200:bodyresult})))))