Liking cljdoc? Tell your friends :D

com.ben-allred.vow.core

A library to wrap core.async channels with chainable left/right (or success/failure) handling.

A library to wrap core.async channels with chainable left/right (or success/failure) handling.
raw docstring

allclj/s

(all promises)

Takes a sequence of promises and returns a promise that resolves when all promises resolve, or rejects if any promise rejects. promises can be a map or sequential collection

(-> {:foo (resolve :bar) :baz (resolve :quux)} (all) (then println)) ;; {:foo :bar :baz :quux}

Takes a sequence of promises and returns a promise that resolves when all promises resolve, or rejects if any
promise rejects. `promises` can be a map or sequential collection

(-> {:foo (resolve :bar) :baz (resolve :quux)}
    (all)
    (then println)) ;; {:foo :bar :baz :quux}
sourceraw docstring

alwaysclj/smacro

(always promise & body)

A macro that always executes a body, regardless of the result of the promise. Evaluates forms in order and returns the last one.

(always my-promise (println "I always happen") 17)

A macro that always executes a body, regardless of the result of the promise. Evaluates forms in order and
returns the last one.

(always my-promise (println "I always happen") 17)
source (clj)source (cljs)raw docstring

andclj/smacro

(and promise & forms)

Continues the promise chain by executing each form in order until one throws or results in a rejected promise. Returns the last success or the first rejection.

Continues the promise chain by executing each form in order until one throws or results in a rejected promise.
Returns the last success or the first rejection.
source (clj)source (cljs)raw docstring

catchclj/s

(catch promise cb)

Handles the failure path of a promise. If the handler fn returns an IPromise, it will be hoisted. If the handler fn throws, it will produce a rejected promise.

Handles the failure path of a promise. If the handler fn returns an IPromise, it will be hoisted.
If the handler fn throws, it will produce a rejected promise.
sourceraw docstring

ch->promclj/s

(ch->prom ch)
(ch->prom ch success?)

Given a core.async channel and an optional success? predicate, creates a promise with the first value pulled off the channel. The promise will resolve or reject according to the result of (success? (async/<! ch)). Defaults to always resolving.

Given a core.async channel and an optional success? predicate, creates a promise with the first value pulled off
the channel. The promise will resolve or reject according to the result of (success? (async/<! ch)). Defaults
to always resolving.
sourceraw docstring

createclj/s

(create cb)

Creates a promise that resolves or rejects at the discretion of cb. cb should be a two arg function accepting resolve and reject that will "resolve" or "reject" the promise respectively.

(create (fn [resolve reject] (let [default (gensym) result (deref (future (do-something)) 1000 default)] (if (= default result) (reject (ex-info "Took too long" {})) (resolve result)))))

Creates a promise that resolves or rejects at the discretion of cb.
`cb` should be a two arg function accepting `resolve` and `reject` that will
"resolve" or "reject" the promise respectively.

(create (fn [resolve reject]
          (let [default (gensym)
                result (deref (future (do-something)) 1000 default)]
            (if (= default result)
              (reject (ex-info "Took too long" {}))
              (resolve result)))))
sourceraw docstring

deref!clj/s

(deref! prom)
(deref! prom timeout-ms timeout-value)

Deref a promise into a value, or cause it to throw an exception - Clojure only.

Deref a promise into a value, or cause it to throw an exception - Clojure only.
sourceraw docstring

native->promclj/s≠

clj
(native->prom prom)
(native->prom prom success?)
cljs
(native->prom prom)

Given a "native" promise (js/Promise in cljs and anything that implements IDeref in clj), creates a promise that resolves or rejects. In cljs it follows js/Promise semantics for resolving and rejecting. In clj you can pass an optional success? predicate that determines whether to resolve or reject the value which always resolves by default.

Given a "native" promise (js/Promise in cljs and anything that implements IDeref in clj), creates a promise
that resolves or rejects. In cljs it follows js/Promise semantics for resolving and rejecting. In clj you can pass
an optional `success?` predicate that determines whether to resolve or reject the value which always resolves by
default.
sourceraw docstring

orclj/smacro

(or promise & forms)

Continues the promise chain by executing each form in order until one returns a value or a resolved promise. Returns the first success or the last rejection.

Continues the promise chain by executing each form in order until one returns a value or a resolved promise.
Returns the first success or the last rejection.
source (clj)source (cljs)raw docstring

peekclj/s

(peek promise cb)
(peek promise on-success on-error)

Access the success and/or failure path of a promise chain at a specific point in processing. Can be used for side effects (or debugging) only. Does not effect the value to be resolved or rejected. If you only want to handle one of success/failure path, pass nil for the other handler.

(peek promise nil println)

Access the success and/or failure path of a promise chain at a specific point in processing. Can be used
for side effects (or debugging) only. Does not effect the value to be resolved or rejected. If you only want
to handle one of success/failure path, pass `nil` for the other handler.

(peek promise nil println)
sourceraw docstring

promise?clj/s

(promise? x)

Returns true if x satisfies IPromise.

Returns `true` if `x` satisfies `IPromise`.
sourceraw docstring

rejectclj/s

(reject)
(reject err)

Creates a promise that rejects with err.

Creates a promise that rejects with `err`.
sourceraw docstring

resolveclj/s

(resolve)
(resolve val)

Creates a promise that resolves with val.

Creates a promise that resolves with `val`.
sourceraw docstring

sleepclj/s

(sleep ms)
(sleep ms value)

Creates a promise that resolves after the specified amount of time (in milliseconds).

Creates a promise that resolves after the specified amount of time (in milliseconds).
sourceraw docstring

thenclj/s

(then promise on-success)
(then promise on-success on-error)

Handles the success path (or success and failure path) of a promise. If the handler fn returns an IPromise, it will be hoisted. If the handler fn throws, it will produce a rejected promise.

Handles the success path (or success and failure path) of a promise. If the handler fn returns
an IPromise, it will be hoisted. If the handler fn throws, it will produce a rejected promise.
sourceraw docstring

then->clj/smacro

(then-> promise & forms)

A macro for handing the success path thread via ->.

(-> (resolve 3) (then-> inc (* 2) (as-> $ (repeat $ $)) (->> (map dec))) (peek println nil)) ;; (7 7 7 7 7 7 7 7)

A macro for handing the success path thread via `->`.

(-> (resolve 3)
    (then-> inc (* 2) (as-> $ (repeat $ $)) (->> (map dec)))
    (peek println nil)) ;; (7 7 7 7 7 7 7 7)
source (clj)source (cljs)raw docstring

vowclj/smacro

(vow & body)

A macro for creating a promise out of an expression

(peek (vow (println "starting") (/ 17 0)) println)

A macro for creating a promise out of an expression

(peek (vow (println "starting") (/ 17 0)) println)
source (clj)source (cljs)raw docstring

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

× close