Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miikka/long-thread
Java threads in Clojure
https://github.com/miikka/long-thread
clojure concurrency threading
Last synced: 26 days ago
JSON representation
Java threads in Clojure
- Host: GitHub
- URL: https://github.com/miikka/long-thread
- Owner: miikka
- Created: 2018-02-14T15:34:21.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2023-06-04T09:45:25.000Z (over 1 year ago)
- Last Synced: 2024-12-17T21:39:57.718Z (about 2 months ago)
- Topics: clojure, concurrency, threading
- Language: Clojure
- Homepage:
- Size: 89.8 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# long-thread [![cljdoc badge](https://cljdoc.org/badge/miikka/long-thread)](https://cljdoc.org/d/miikka/long-thread/CURRENT)
A Clojure library for starting and stopping threads. Basically just a wrapper for
`java.lang.Thread`.## Latest version
[![Clojars Project](https://clojars.org/miikka/long-thread/latest-version.svg)](https://clojars.org/miikka/long-thread)
## Why?
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.## Usage
* [API reference](https://cljdoc.org/d/miikka/long-thread/CURRENT)
```clojure
(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)))
```## Acknowledgements
The inspiration for this work is `zthread.clj`, a similar library developed by
Joel Kaasinen and others at ZenRobotics.## See also
* For value-returning one-off tasks, see Clojure's futures, [manifold's futures](http://aleph.io/manifold/deferreds.html#future-vs-manifold-deferred-future), or [java.util.concurrent.ExecutorService](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html).
* For scheduled tasks (e.g. run once in every minute), see [manifold.time](https://aleph.io/codox/manifold/manifold.time.html), Duct's [scheduler.simple](https://github.com/duct-framework/scheduler.simple), and [ScheduledThreadPoolExecutor](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html).## Development guide
* Run tests with `lein test`
* Generate a test coverage report with `lein cloverage` and look at `target/coverage/index.html`.## License
Copyright Miikka Koskinen.
Available under the terms of the Eclipse Public License 2.0, see `LICENSES/EPL-2.0.txt`.