A library to simplify working with Java threads from clojure.
Clojure Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/pallet/thread
test/pallet/thread
.gitignore
.travis.yml
README.md
ReleaseNotes.md
finish-release.sh
project.clj
start-release.sh

README.md

pallet-thread

A library to simplify working with Java threads from clojure.

Usage

To create a cached thread pool, and run something:

(use 'pallet.thread.executor)
(let [pool (executor {:prefix "mypool" :thread-group-name "mypool"})
      f (execute pool #(+ 1 2))]
  (println @f)

You can create a fixed size thread pool:

(use 'pallet.thread.executor)
(executor {:pool-size 2 :prefix "mypool" :thread-group-name "mypool"})

There are also scheduled executors:

(use 'pallet.thread.executor)
(with-executor [pool (executor {:prefix "mypool" :scheduled true :pool-size 1})]
  (let [_ (execute-after pool #(println "hello") 1000 :ms)
        _ (execute-after pool #(println "there") 2 :s)
        f1 (execute-fixed-rate pool #(println ".") 1 :s 2)
        f2 (execute-fixed-delay pool #(println "!") 2 :s 2)]
    (Thread/sleep 10000)
    (future-cancel f1)
    (future-cancel f2)))

API docs

Installation

To use pallet-thread, add the following to your :dependencies:

[pallet-thread "0.1.0"]

Build Status

License

Copyright © 2012 Hugo Duncan

Distributed under the Eclipse Public License.