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

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)
source

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

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

promiseclj/smacro

(promise & body)

A macro for creating a promise out of an expression

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

A macro for creating a promise out of an expression

(peek (promise (println "starting") (/ 17 0)) println)
source (clj)source (cljs)raw 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

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

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

× close