A Clojure library for starting and stopping threads. Basically just a wrapper for
java.lang.Thread
.
Clojure has plenty fancy tools such as futures for concurrent programming.
However, sometimes what you need is a good old thread. You could use Java's
Thread
directly, but the purpose of this wrapper is to encourage good
practices such as always naming your threads.
(ns example.core
(:require [long-thread.core :as long-thread]))
(defn my-loop
[]
(long-thread/until-interrupted
(println "This is your regularly scheduled greeting: Hello!")
(Thread/sleep 1000)))
(defn main
[]
(let [my-thread (long-thread/create "greetings thread" my-loop)]
(println "Press enter to stop...")
(read-line)
(long-thread/stop my-thread)))
The inspiration for this work is zthread.clj
, a similar library developed by
Joel Kaasinen and others at ZenRobotics.
- For value-returning one-off tasks, see Clojure's futures, manifold's futures, or java.util.concurrent.ExecutorService.
- For scheduled tasks (e.g. run once in every minute), see manifold.time, Duct's scheduler.simple, and ScheduledThreadPoolExecutor.
- Run tests with
lein test
- Generate a test coverage report with
lein cloverage
and look attarget/coverage/index.html
.
Copyright Miikka Koskinen.
Available under the terms of the Eclipse Public License 2.0, see LICENSES/EPL-2.0.txt
.