Thin wrapper around Java Executors/Threads, including executors aware
versions of future
and future-call
.
via tools.deps
- Breaking changes : there are no longer a single arg versions of
knit/future
andknit/thread
, just useclojure.core
equivalents in these cases. Also the multi arg version of these 2 macros now takes the option map as last argument instead of first.
(use 'qbits.knit)
Executor can be :fixed
:cached
:single
:scheduled
:scheduled-single
:thread-per-task
:virtual
,
matching the corresponding Java instances.
(def x (executor :fixed))
With all options
(def x (executor :fixed {:num-threads 3 :thread-factory a-thread-factory}))
Submit a task to executor
(submit x #(println "Hello World"))
(def tf (thread-factory))
With all options
(def a-thread-group (thread-group "knit-group"))
(def tf (thread-factory {:thread-group a-thread-group
:daemon false}))
Identical to the Java version
(thread-group "name")
(thread-group parent-group "name")
(schedule :at-fixed-rate 200 #(println "hello world"))
Supports :at-fixed-rate
:with-fixed-delay
:once
, matching the
corresponding Java methods.
With all options:
(schedule :at-fixed-rate 2 #(println "hello world")
{:initial-delay 1
:executor (executor :scheduled
:num-threads 3
:thread-factory a-thread-factory)
:unit :minutes})
Time units are :days
:hours
:minutes
:seconds
:milliseconds
:microseconds
:nanoseconds
(qbits.knit/future (System/currentTimeMillis) {:executor x})
(qbits.knit/future-call #(System/currentTimeMillis) {:executor x})
## License
Copyright © 2015 Max Penet
Distributed under the Eclipse Public License, the same as Clojure.