Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn scheduler []
- "Create an executor for executing fns in an own thread."
- (let [executor (Executors/newSingleThreadScheduledExecutor)]
- (fn
- ([k]
- (cond
- (= k :stop) (.shutdown executor)
- (= k :stop-now) (.shutdownNow executor)))
- ([k f d]
- (cond
- (= k :once) (.schedule executor f d TimeUnit/MILLISECONDS)
- (= k :repeat) (.scheduleAtFixedRate executor f 0 d TimeUnit/MILLISECONDS)))
- ([k f id d]
- (cond
- (= k :repeat) (.scheduleAtFixedRate executor f id d TimeUnit/MILLISECONDS))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement