Liking cljdoc? Tell your friends :D

safely.thread-pool


async-execute-with-poolclj

(async-execute-with-pool pool thunk)

It returns a promise which will deliver tuple of 3 values where the first value is a the result of the execution of the thunk. The second value is nil when the execution is successful or :error if the thunk throws an exception, and :queue-full when the thread pool can't accent any more tasks.

It returns a promise which will deliver tuple of 3 values where the
first value is a the result of the execution of the thunk. The
second value is `nil` when the execution is successful or `:error`
if the thunk throws an exception, and `:queue-full` when the thread
pool can't accent any more tasks.
sourceraw docstring

cancelclj

(cancel task & {:keys [force] :or {force false}})

Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the :force true parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

Returns false if the task could not be cancelled, typically because it has already completed normally; true if the cancellation was requested and nil if the task was not cancellable.

Attempts to cancel execution of this task. This attempt will fail if
the task has already completed, has already been cancelled, or could
not be cancelled for some other reason. If successful, and this task
has not started when cancel is called, this task should never
run. If the task has already started, then the `:force true`
parameter determines whether the thread executing this task should
be interrupted in an attempt to stop the task.

Returns `false` if the task could not be cancelled, typically
because it has already completed normally; `true` if the
cancellation was requested and `nil` if the task was not
cancellable.
sourceraw docstring

execute-with-poolclj

(execute-with-pool pool
                   timeout
                   thunk
                   &
                   {:keys [cancel-on-timeout] :or {cancel-on-timeout :always}})

It returns a promise which will deliver tuple of 3 values where the first value is a the result of the execution of the thunk. The second value is nil when the execution is successful or :error if the thunk throws an exception,:queue-full when the thread pool can't accent any more tasks, and :timeout when a timeout was reached.

It returns a promise which will deliver tuple of 3 values where the
first value is a the result of the execution of the thunk. The
second value is `nil` when the execution is successful or `:error`
if the thunk throws an exception,`:queue-full` when the thread
pool can't accent any more tasks, and `:timeout` when a timeout
was reached.
sourceraw docstring

fixed-thread-poolclj

(fixed-thread-pool name size & {:keys [queue-size] :as opts})
source

running-task-countclj

(running-task-count tp)

Returns the approximate count of in flight tasks

Returns the approximate count of in flight tasks
sourceraw docstring

threadcljmacro

(thread & body)
(thread name & body)
(thread {:keys [name daemon priority auto-start]} & body)

It creates a thread and run the give thunk in the new thread. It returns a promise of a result, it's similar to a future, but you can control the thread name, priority etc. If auto-start is true then the thread is started after its creation; if false then instead of returning a promise with the result it return a function with no arguments which when called it starts the thread and return the promise. All exception are caught and returned as result.

examples:

```
;; create and start a thread named `runner`
(thread "runner"
    (println "Hi from runner!"))
;;=> nil
```

```
;; create and start a thread named `runner` and get the result
@(thread {:name "runner"}
    (reduce + (range 1000)))
;;=> 499500
```

```
;; create and start a thread named `runner`
(def t
  (thread {:name "runner" :auto-start false}
      (reduce + (range 1000))))
;; call the function to start the thread, deref for the result
@(t)
;;=> 499500
```

```
;; exceptions are retuned as result
@(thread "bad-runner"
    (/ 1 0))
;; it captures and returns the exception
;;=> java.lang.ArithmeticException("Divide by zero")
```
It creates a thread and run the give thunk in the new thread.
It returns a promise of a result, it's similar to a future, but you
can control the thread name, priority etc.  If `auto-start` is
`true` then the thread is started after its creation; if `false`
then instead of returning a promise with the result it return a
function with no arguments which when called it starts the thread
and return the promise. All exception are caught and returned as
result.

examples:

    ```
    ;; create and start a thread named `runner`
    (thread "runner"
        (println "Hi from runner!"))
    ;;=> nil
    ```

    ```
    ;; create and start a thread named `runner` and get the result
    @(thread {:name "runner"}
        (reduce + (range 1000)))
    ;;=> 499500
    ```

    ```
    ;; create and start a thread named `runner`
    (def t
      (thread {:name "runner" :auto-start false}
          (reduce + (range 1000))))
    ;; call the function to start the thread, deref for the result
    @(t)
    ;;=> 499500
    ```

    ```
    ;; exceptions are retuned as result
    @(thread "bad-runner"
        (/ 1 0))
    ;; it captures and returns the exception
    ;;=> java.lang.ArithmeticException("Divide by zero")
    ```

sourceraw docstring

thread*clj

(thread* {:keys [name daemon priority auto-start]
          :or {name "safely-custom-thread" daemon false auto-start true}}
         thunk)

It creates a thread and run the give thunk in the new thread. It returns a promise of a result, it's similar to a future, but you can control the thread name, priority etc. If auto-start is true then the thread is started after its creation; if false then instead of returning a promise with the result it return a function with no arguments which when called it starts the thread and return the promise. All exception are caught and returned as result.

examples:

```
;; create and start a thread named `runner`
(thread* {:name "runner"}
  (fn []
    (println "Hi from runner!")))
;;=> nil
```

```
;; create and start a thread named `runner` and get the result
@(thread* {:name "runner"}
  (fn []
    (reduce + (range 1000))))
;;=> 499500
```

```
;; create and start a thread named `runner`
(def t
  (thread* {:name "runner" :auto-start false}
    (fn []
      (reduce + (range 1000)))))
;; call the function to start the thread, deref for the result
@(t)
;;=> 499500
```

```
;; exceptions are retuned as result
@(thread* {:name "bad-runner"}
  (fn []
    (/ 1 0)))
;; it capture and returns the exception
;;=> java.lang.ArithmeticException("Divide by zero")
```
It creates a thread and run the give thunk in the new thread.
It returns a promise of a result, it's similar to a future, but you
can control the thread name, priority etc.  If `auto-start` is
`true` then the thread is started after its creation; if `false`
then instead of returning a promise with the result it return a
function with no arguments which when called it starts the thread
and return the promise. All exception are caught and returned as
result.

examples:

    ```
    ;; create and start a thread named `runner`
    (thread* {:name "runner"}
      (fn []
        (println "Hi from runner!")))
    ;;=> nil
    ```

    ```
    ;; create and start a thread named `runner` and get the result
    @(thread* {:name "runner"}
      (fn []
        (reduce + (range 1000))))
    ;;=> 499500
    ```

    ```
    ;; create and start a thread named `runner`
    (def t
      (thread* {:name "runner" :auto-start false}
        (fn []
          (reduce + (range 1000)))))
    ;; call the function to start the thread, deref for the result
    @(t)
    ;;=> 499500
    ```

    ```
    ;; exceptions are retuned as result
    @(thread* {:name "bad-runner"}
      (fn []
        (/ 1 0)))
    ;; it capture and returns the exception
    ;;=> java.lang.ArithmeticException("Divide by zero")
    ```

sourceraw docstring

thread-factoryclj

(thread-factory prefix daemon uncaught-exception-handler)

Creates a thread factory which creates threads with the given prefix and a incremental counter. The threads can be created as daemon.

Creates a thread factory which creates threads
with the given prefix and a incremental counter.
The threads can be created as daemon.
sourceraw docstring

thread-poolclj

(thread-pool {:keys [name core-size max-size keep-alive-time queue-size]
              :or {name "safely.unnamed"
                   core-size 5
                   max-size 10
                   keep-alive-time 60000
                   queue-size 50}})

Creates a thread pool.

Creates a thread pool.
sourceraw docstring

timeout-waitclj

(timeout-wait value timeout cancel-strategy)

It waits on a async value up to a given timeout. If the timeout is elapsed and the value is not available yet, then then the task is cancelled according to the cancel-strategy. accepted values: :never, :if-not-running or :always

It waits on a  async value up to a given timeout.
If the timeout is elapsed and the value is not available yet, then
then the task is cancelled according to the `cancel-strategy`.
accepted values: `:never`, `:if-not-running` or `:always`
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close