Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

26 lines (22 sloc) 1.111 kB
(ns foreclojure.periodic
(:import (java.util.concurrent ScheduledThreadPoolExecutor
ScheduledExecutorService
TimeUnit)))
;; Stolen from clojail, but I wrote it myself anyway.
;; I guess it deserves a library of its own? Or maybe in useful?
(def uglify-time-unit
(into {} (for [[enum aliases] {TimeUnit/NANOSECONDS [:ns :nanoseconds]
TimeUnit/MICROSECONDS [:us :microseconds]
TimeUnit/MILLISECONDS [:ms :milliseconds]
TimeUnit/SECONDS [:s :sec :seconds]
TimeUnit/MINUTES [:m :min :minutes]
TimeUnit/HOURS [:h :hours]
TimeUnit/DAYS [:d :days]}
alias aliases]
{alias enum})))
(def ^ScheduledExecutorService pool
(memoize (fn []
(ScheduledThreadPoolExecutor. 2))))
(defn schedule-task [task period unit]
(.scheduleAtFixedRate (pool) task 0
period (uglify-time-unit unit)))
Jump to Line
Something went wrong with that request. Please try again.