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.
(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}
(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.
(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.
(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)))))
(native->prom prom)
(native->prom prom success?)
(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.
(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)
(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)
(promise? x)
Returns true
if x
satisfies IPromise
.
Returns `true` if `x` satisfies `IPromise`.
(reject)
(reject err)
Creates a promise that rejects with err
.
Creates a promise that rejects with `err`.
(resolve)
(resolve val)
Creates a promise that resolves with val
.
Creates a promise that resolves with `val`.
(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.
(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)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close