CrossClj

0.3.1 docs

SourceDocs



RECENT

    cc.qbits/knit

    Clojars

    Jan 18, 2016


    OWNER
    Max Penet
    finity.ai - MapRedux AB - qbits.cc
    Eslöv, Sweden - Geneva, Switzerland
    m@qbits.cc
    qbits.cc

    Readme

    Index of all namespaces


    The README below is fetched from the published project artifact. Some relative links may be broken.

    knit Build Status

    Thin wrapper around Java Executors/Threads, including executors aware versions of future, clojure.core.async/thread, clojure.core.async/thread-call and future-call.

    Installation

    [cc.qbits/knit "0.3.1"]
    

    Usage

    (use 'qbits.knit)
    

    Executors

    Executor can be :fixed :cached :single :scheduled, 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

    (execute x #(println "Hello World"))
    

    ThreadFactory

    (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}))
    

    ThreadGroup

    Identical to the Java version

    (thread-group "name")
    (thread-group parent-group "name")
    

    ScheduledFuture

    (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

    Clojure like future and core.async/thread* with configurable execution context

    (qbits.knit/future {:executor x} (System/currentTimeMillis))
    (qbits.knit/future-call #(System/currentTimeMillis) {:executor x})
    
    ;; core.async/thread
    (qbits.knit/thread {:executor x} (System/currentTimeMillis))
    (qbits.knit/thread-call #(System/currentTimeMillis) {:executor x})
    

    License

    Copyright © 2015 Max Penet

    Distributed under the Eclipse Public License, the same as Clojure.