Liking cljdoc? Tell your friends :D

knitty.deferred


altclj

(alt a)
(alt a b)
(alt a b c)
(alt a b c d)
(alt a b c d & vs)

Takes several values, some of which may be a deferred, and returns a deferred that will yield the value which was realized first.

Takes several values, some of which may be a deferred, and returns a
deferred that will yield the value which was realized first.
raw docstring

await!cljmacro

(await! ls & ds)

await!*clj

(await!* ls ds)

Like await! but accept iterable collection of deferreds.

Like `await!` but accept iterable collection of deferreds.
raw docstring

bindclj

(bind d val-fn)
(bind d val-fn err-fn)

Bind 1-arg callbacks fn to deferred. Returns new deferred with amended value. Fn val-fn takes single arugment with unwrapped value and may return a new value, another deferred or throw an exception. Optional err-fn accepts single argument with error.

Bind 1-arg callbacks fn to deferred. Returns new deferred with amended value.
Fn `val-fn` takes single arugment with unwrapped value and may return a new value,
another deferred or throw an exception. Optional `err-fn` accepts single argument with error.
raw docstring

bind->cljmacro

(bind-> expr & forms)

Combination of bind and threading macro ->. Similar to manifold.deferred/chain, but does not allow dynamic applying with seq of arguments. Use reduce if number of binded callbacks is known only at runtime.

Combination of `bind` and threading macro `->`.
Similar to `manifold.deferred/chain`, but does not allow dynamic applying with seq of arguments.
Use `reduce` if number of binded callbacks is known only at runtime.
raw docstring

bind-errclj

(bind-err mv f)
(bind-err mv exc f)

Bind 1-arg callback fn to deferred. Callback called when deferred is realized with an error. Use throw to re-throw error or return a new value. Optinal argument exc may specify which kind of errors we want to handle. It may be 1-arg predicate fn, subclass of java.lang.Throwable or map. In the last case only instances of IExceptionInfo are handled where their ex-data is a subset of the exc map.

(-> d
  (bind-err java.lang.IOException       #(handle-instances-of-ioexception %))
  (bind-err #(re-find #"text" (str %))  #(hande-exceptions-with-matched-text %))
  (bind-err {:type :my-error}           #(hande-exinfo-with-matched-type %))
  (bind-err                             #(handle-any-error %)))
Bind 1-arg callback fn to deferred. Callback called when deferred is realized with an error.
Use `throw` to re-throw error or return a new value.
Optinal argument `exc` may specify which kind of errors we want to handle.
It may be 1-arg predicate fn, subclass of java.lang.Throwable or map.
In the last case only instances of `IExceptionInfo` are handled where their `ex-data` is a subset of the `exc` map.

    (-> d
      (bind-err java.lang.IOException       #(handle-instances-of-ioexception %))
      (bind-err #(re-find #"text" (str %))  #(hande-exceptions-with-matched-text %))
      (bind-err {:type :my-error}           #(hande-exinfo-with-matched-type %))
      (bind-err                             #(handle-any-error %)))
raw docstring

bind-exclj

(bind-ex d executor val-fn)
(bind-ex d executor val-fn err-fn)

Similar to bind, but run all callbacks on specified executor.

Similar to `bind`, but run all callbacks on specified `executor`.
raw docstring

bind-finclj

(bind-fin d f0)

Bind 0-arg function to be executed when deferred is realized (either with value or error). Callback result is ignored, any thrown execiptions are re-wrapped.

Bind 0-arg function to be executed when deferred is realized (either with value or error).
Callback result is ignored, any thrown execiptions are re-wrapped.
raw docstring

call-after-all-arr'cljmacro

(call-after-all-arr' ds-arr f)

chain*clj

(chain* x fs)

Composes functions over the value x, returning a deferred containing the result.

Composes functions over the value `x`, returning a deferred containing the result.
raw docstring

claim!clj

(claim! d)
(claim! d token)

Attempts to claim the deferred for future updates.

Attempts to claim the deferred for future updates.
raw docstring

connectclj

(connect d-from d-dest)

Conveys the realized value of d-from into d-dest.

Conveys the realized value of `d-from` into `d-dest`.
raw docstring

createclj

(create)
(create token)

Create a new unrealized deferred.

Create a new unrealized deferred.
raw docstring

deferred?clj

(deferred? x)

Returns true if the object is an instance of a deferred.

Returns true if the object is an instance of a deferred.
raw docstring

do-wrapcljmacro

(do-wrap & body)

Run body and returns value as deferred, catch and wrap any exceptions.

Run `body` and returns value as deferred, catch and wrap any exceptions.
raw docstring

error!cljmacro

(error! d x)
(error! d x token)

Puts a deferred into a realized state with provided error x.

Puts a deferred into a realized state with provided error `x`.
raw docstring

futurecljmacro

(future & body)

Equivalent to clojure.core/future, but returns a Knitty deferred.

Equivalent to `clojure.core/future`, but returns a Knitty deferred.
raw docstring

future-callclj

(future-call f)

Equivalent to clojure.core/future-call, but returns a Knitty deferred.

Equivalent to `clojure.core/future-call`, but returns a Knitty deferred.
raw docstring

impl-iterate-while*cljmacro

(impl-iterate-while* init f p)
(impl-iterate-while* init
                     [fn1 [stepf-x] & stepf-body]
                     [fn2 [somef-x] & somef-body]
                     [fn3 [retrn-x] & retrn-body])

iterate-whileclj

(iterate-while stepf somef init)

Iteratively run 1-arg function f with initial value x. After each call check result of calling p and stop loop when result if falsy. Function f may return deferreds, initial value x also may be deferred. Predicate p should always return synchonous values howerver. This is low-level routine, prefer reduce while or loop.

Iteratively run 1-arg function `f` with initial value `x`.
After each call check result of calling `p` and stop loop when result if falsy.
Function `f` may return deferreds, initial value `x` also may be deferred.
Predicate `p` should always return synchonous values howerver.
This is low-level routine, prefer `reduce` `while` or `loop`.
raw docstring

joinclj

(join d)

Coerce 'deferred with deferred value' to deferred with plain value.

@(join (kd/future (kd/future (kd/future 1)))) ;; => 1

Coerce 'deferred with deferred value' to deferred with plain value.

@(join (kd/future (kd/future (kd/future 1))))  ;; => 1
raw docstring

join1clj

(join1 d)

Coerce 'deferred with deferred value' to deferred with plain value.

@(join1 (kd/future (kd/future 1))) ;; => 1

Coerce 'deferred with deferred value' to deferred with plain value.

@(join1 (kd/future (kd/future 1)))  ;; => 1
raw docstring

kd-await!cljmacro

(kd-await! ls)
(kd-await! ls x1)
(kd-await! ls x1 & xs)

Internal macros used by yarns - prefer not to use it. Schedlue 0/1-arg function ls to execute after all deferreds are realized with values or at least one deferred is realized with an error. All deferreds must be instances of Knitty deferred (use wrap or wrap* for coercion).

Internal macros used by yarns - prefer not to use it.
Schedlue 0/1-arg function `ls` to execute after all deferreds are realized
with values or at least one deferred is realized with an error.
All deferreds *must* be instances of Knitty deferred (use `wrap` or `wrap*` for coercion).
raw docstring

kd-succeeded?cljmacro

(kd-succeeded?)
(kd-succeeded? x1 & xs)

Internal macros used by yarns - prefer not to use it. Returns true when all instances of KDeferred are realized with values.

Internal macros used by yarns - prefer not to use it.
Returns `true` when all instances of KDeferred are realized with values.
raw docstring

letmcljmacro

(letm binds & body)

Monadic let. Unwraps deferreds during binding, returning result as deferred. Unlike manifold.deferred/let-flow all steps are resolved in sequential order, so use zip if parallel execution is required. Steps list can contain :let and :when special forms.

(letm [[x y] (zip (kd/future (rand) (kd/future (rand))) :when (< x y) ;; whole letm returns nil when condition is not met :let [d x] ;; bind without unwrapping z (kd/future (* x y))] (vector x y z @d))

Monadic let. Unwraps deferreds during binding, returning result as deferred.
Unlike `manifold.deferred/let-flow` all steps are resolved in sequential order,
so use `zip` if parallel execution is required.
Steps list can contain :let and :when special forms.

 (letm [[x y] (zip (kd/future (rand) (kd/future (rand)))
        :when (< x y)  ;; whole letm returns nil when condition is not met
        :let [d x]     ;; bind without unwrapping
        z (kd/future (* x y))]
   (vector x y z @d))
raw docstring

loopcljmacro

(loop bindings & body)

A version of Clojure's loop which allows for asynchronous loops, via manifold.deferred/recur. loop will always return a deferred value, even if the body is synchronous. Note that loop does not coerce values to deferreds, actual Manifold deferreds must be used.

(loop [i 1e6] (chain (future i) #(if (p/zero? %) % (recur (p/dec %)))))

A version of Clojure's loop which allows for asynchronous loops, via `manifold.deferred/recur`.
`loop` will always return a deferred value, even if the body is synchronous.  Note that `loop`
 does **not** coerce values to deferreds, actual Manifold deferreds must be used.

 (loop [i 1e6]
   (chain (future i)
     #(if (p/zero? %)
        %
        (recur (p/dec %)))))
raw docstring

onclj

(on x on-any)
(on x on-ok on-err)

Registers callback fns to run when deferred is realized. When only one callback is provided it shold be 0-arg fn. When both callbacks provided - they must accept 1 argument (value or error).

Registers callback fns to run when deferred is realized.
When only one callback is provided it shold be 0-arg fn.
When both callbacks provided - they must accept 1 argument (value or error).
raw docstring

ontoclj

(onto d executor)

Returns a deferred whose callbacks will be run on executor.

Returns a deferred whose callbacks will be run on `executor`.
raw docstring

recurcljmacro

(recur & args)

A special recur that can be used with knitty.deferred/loop.

A special recur that can be used with `knitty.deferred/loop`.
raw docstring

reduceclj

(reduce f initd xs)

Deferred-aware version of clojure.core/reduce. Step function f may return deferred values, xs may be sequence of deferreds.

Deferred-aware version of `clojure.core/reduce`.
Step function `f` may return deferred values, `xs` may be sequence of deferreds.
raw docstring

revokeclj

(revoke d cancel-fn)
(revoke d cancel-fn err-handler)

Returns new deferred connected to the provided. When resulted deferred is realized but original is not - calls cancellation callback.

(let [f (java.core/future (Thread/sleep 1000) 1))
      x (-> (wrap* f)
            (bind inc)
            (revoke #(do
                       (println :operation-is-cancelled)
                       (clojure.core/future-cancel))))]
  (success! x 1)
  (assert (clojure.core/future-cancelled? f)))

Note that call to revoke should be last in a chain, because revokation is not propagated by binding fns.

(let [f (java.core/future (Thread/sleep 1000) 1))
      x (-> (wrap* f)
            (revoke #(do
                       (println :operation-is-cancelled)
                       (clojure.core/future-cancel)))
            (bind inc))]
  (success! x 1)
  ;; revokation was not pass through `(bind inc)` binding.
  (assert (not (clojure.core/future-cancelled? f))))
Returns new deferred connected to the provided.
When resulted deferred is realized but original is not - calls cancellation callback.

    (let [f (java.core/future (Thread/sleep 1000) 1))
          x (-> (wrap* f)
                (bind inc)
                (revoke #(do
                           (println :operation-is-cancelled)
                           (clojure.core/future-cancel))))]
      (success! x 1)
      (assert (clojure.core/future-cancelled? f)))

Note that call to `revoke` should be last in a chain, because revokation is not propagated by binding fns.

    (let [f (java.core/future (Thread/sleep 1000) 1))
          x (-> (wrap* f)
                (revoke #(do
                           (println :operation-is-cancelled)
                           (clojure.core/future-cancel)))
                (bind inc))]
      (success! x 1)
      ;; revokation was not pass through `(bind inc)` binding.
      (assert (not (clojure.core/future-cancelled? f))))

raw docstring

revoke-toclj

(revoke-to d rd)
(revoke-to d rd & rds)

Like revoke, but resolves rd with an exception instead of calling generic callback. Use it to bypass revokation to original deferred:

(let [x (call-some-function)]
  (-> x
     (bind #(process-x1 %))
     (bind #(procces-x2 %))
     (bind-err #(handle-error %))
     (revoke-to x)  ;; bypass cancelation to `x`
     ))
Like `revoke`, but resolves `rd` with an exception instead of calling generic callback.
Use it to bypass revokation to original deferred:

    (let [x (call-some-function)]
      (-> x
         (bind #(process-x1 %))
         (bind #(procces-x2 %))
         (bind-err #(handle-error %))
         (revoke-to x)  ;; bypass cancelation to `x`
         ))
raw docstring

run!clj

(run! f xs)

Sequentially apply f to sequence of deferreds xs for side effects. Fn f may return deferreds.

Sequentially apply `f` to sequence of deferreds `xs` for side effects.
Fn `f` may return deferreds.
raw docstring

success!cljmacro

(success! d x)
(success! d x token)

Puts a deferred into a realized state with provided value x.

Puts a deferred into a realized state with provided value `x`.
raw docstring

unwrapclj

(unwrap x)

Unwraps deferred (once). Returns realized value or the deferred itself.

Unwraps deferred (once). Returns realized value or the deferred itself.
raw docstring

unwrap1clj

(unwrap1 x)

Unwraps deferred (once). Returns realized value or the deferred itself.

Unwraps deferred (once). Returns realized value or the deferred itself.
raw docstring

whilecljmacro

(while body)
(while pred & body)

Deferred-aware version of clojure.core/while. Both test and body experssion may result into deferred. Returns deferred realized to nil.

Deferred-aware version of `clojure.core/while`.
Both test and body experssion may result into deferred.
Returns deferred realized to `nil`.
raw docstring

wrapclj

(wrap x)

Coerce type x from IDeferred to Knitty deferred or returns realized deferred with value x.

Coerce type `x` from IDeferred to Knitty deferred or returns realized deferred with value `x`.
raw docstring

wrap*clj

(wrap* x)

Corece x into an instance of Knitty deferred. Converts non-deferred futures with manifold.deferred/->deferred.

Corece `x` into an instance of Knitty deferred.  Converts non-deferred futures with `manifold.deferred/->deferred`.
raw docstring

wrap-errclj

(wrap-err e)

A realized deferred with error.

A realized deferred with error.
raw docstring

wrap-valclj

(wrap-val v)

A realized deferred with value.

A realized deferred with value.
raw docstring

zipclj

(zip)
(zip a)
(zip a b)
(zip a b c)
(zip a b c d)
(zip a b c d e)
(zip a b c d e f)
(zip a b c d e f g)
(zip a b c d e f g h)
(zip a b c d e f g h i)
(zip a b c d e f g h i j)
(zip a b c d e f g h i j k)
(zip a b c d e f g h i j k l)
(zip a b c d e f g h i j k l m)
(zip a b c d e f g h i j k l m n)
(zip a b c d e f g h i j k l m n o)
(zip a b c d e f g h i j k l m n o p)
(zip a b c d e f g h i j k l m n o p & z)

Takes several values and returns a deferred that will yield vector of realized values.

Takes several values and returns a deferred that will yield vector of realized values.
raw docstring

zip*clj

(zip* vs)
(zip* a vs)
(zip* a b vs)
(zip* a b c vs)
(zip* a b c d vs)
(zip* a b c d e & vs)

Similar to (apply zip vs), returns a seq instead of vector.

Similar to `(apply zip vs)`, returns a seq instead of vector.
raw docstring

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

× close