Liking cljdoc? Tell your friends :D

manifold.deferred

Methods for creating, transforming, and interacting with asynchronous values.

Methods for creating, transforming, and interacting with asynchronous values.
raw docstring

->deferredclj

(->deferred x)
(->deferred x default-val)

Transforms x into a deferred if possible, or returns default-val. If no default value is given, an IllegalArgumentException is thrown.

Transforms `x` into a deferred if possible, or returns `default-val`.  If no default value
is given, an `IllegalArgumentException` is thrown.
raw docstring

add-listener!clj

(add-listener! deferred listener)

Registers a listener which can be cancelled via cancel-listener!. Unless this is useful, prefer on-realized.

Registers a listener which can be cancelled via `cancel-listener!`.  Unless this is useful, prefer `on-realized`.
raw docstring

altclj

(alt & vals)

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

@(alt 1 2) => 1 @(alt (future (Thread/sleep 1) 1) (future (Thread/sleep 1) 2)) => 1 or 2 depending on the thread scheduling

The values are not tried in-order, but iterated over with an initial random shuffle.

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

  @(alt 1 2) => 1
  @(alt (future (Thread/sleep 1) 1)
        (future (Thread/sleep 1) 2)) => 1 or 2 depending on the thread scheduling

The values are not tried in-order, but iterated over with an initial random shuffle.
raw docstring

alt'clj

(alt' & vals)

Like alt, but only unwraps Manifold deferreds.

Like `alt`, but only unwraps Manifold deferreds.
raw docstring

cancel-listener!clj

(cancel-listener! deferred listener)

Cancels a listener which has been registered via add-listener!.

Cancels a listener which has been registered via `add-listener!`.
raw docstring

catchclj

(catch x error-handler)
(catch x error-class error-handler)

An equivalent of the catch clause, which takes an error-handler function that will be invoked with the exception, and whose return value will be yielded as a successful outcome. If an error-class is specified, only exceptions of that type will be caught. If not, all exceptions will be caught.

(-> d
  (chain f g h)
  (catch IOException #(str "oh no, IO: " (.getMessage %)))
  (catch             #(str "something unexpected: " (.getMessage %))))
An equivalent of the catch clause, which takes an `error-handler` function that will be invoked
with the exception, and whose return value will be yielded as a successful outcome.  If an
`error-class` is specified, only exceptions of that type will be caught.  If not, all exceptions
will be caught.

    (-> d
      (chain f g h)
      (catch IOException #(str "oh no, IO: " (.getMessage %)))
      (catch             #(str "something unexpected: " (.getMessage %))))

 
raw docstring

catch'clj

(catch' x error-handler)
(catch' x error-class error-handler)

Like catch, but does not coerce deferrable values.

Like `catch`, but does not coerce deferrable values.
raw docstring

chainclj

(chain x)
(chain x f)
(chain x f g)
(chain x f g & fs)

Composes functions, left to right, over the value x, returning a deferred containing the result. When composing, either x or the returned values may be values which can be converted to a deferred, causing the composition to be paused.

The returned deferred will only be realized once all functions have been applied and their return values realized.

@(chain 1 inc #(future (inc %))) => 3

@(chain (future 1) inc inc) => 3
Composes functions, left to right, over the value `x`, returning a deferred containing
the result.  When composing, either `x` or the returned values may be values which can
be converted to a deferred, causing the composition to be paused.

The returned deferred will only be realized once all functions have been applied and their
return values realized.

    @(chain 1 inc #(future (inc %))) => 3

    @(chain (future 1) inc inc) => 3

raw docstring

chain'clj

(chain' x)
(chain' x f)
(chain' x f g)
(chain' x f g & fs)

Like chain, but does not coerce deferrable values. This is useful both when coercion is undesired, or for 2-4x better performance than chain.

Like `chain`, but does not coerce deferrable values.  This is useful both when coercion
is undesired, or for 2-4x better performance than `chain`.
raw docstring

claim!clj

(claim! deferred)

Attempts to claim the deferred for future updates. If successful, a claim token is returned, otherwise returns nil.

Attempts to claim the deferred for future updates.  If successful, a claim token is returned, otherwise returns `nil`.
raw docstring

connectclj

(connect a b)

Conveys the realized value of a into b.

Conveys the realized value of `a` into `b`.
raw docstring

Deferrablecljprotocol


deferrable?clj

(deferrable? x)

Returns true if the object can be coerced to a Manifold deferred.

Returns true if the object can be coerced to a Manifold deferred.
raw docstring

deferredclj

(deferred)
(deferred executor)

Equivalent to Clojure's promise, but also allows asynchronous callbacks to be registered and composed via chain.

Equivalent to Clojure's `promise`, but also allows asynchronous callbacks to be registered
and composed via `chain`.
raw docstring

deferred?clj

(deferred? x)

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

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

error!clj

(error! deferred x)
(error! deferred x claim-token)

Puts the deferred into an error state.

Puts the deferred into an error state.
raw docstring

error-deferredclj

(error-deferred error)
(error-deferred error executor)

A deferred which already contains a realized error

A deferred which already contains a realized error
raw docstring

finallyclj

(finally x f)

An equivalent of the finally clause, which takes a no-arg side-effecting function that executes no matter what the result.

An equivalent of the finally clause, which takes a no-arg side-effecting function that executes
no matter what the result.
raw docstring

finally'clj

(finally' x f)

Like finally, but doesn't coerce deferrable values.

Like `finally`, but doesn't coerce deferrable values.
raw docstring

futurecljmacro

(future & body)

Equivalent to Clojure's future, but returns a Manifold deferred.

Equivalent to Clojure's `future`, but returns a Manifold deferred.
raw docstring

future-withcljmacro

(future-with executor & body)

Equivalent to Clojure's future, but allows specification of the executor and returns a Manifold deferred.

Equivalent to Clojure's `future`, but allows specification of the executor
and returns a Manifold deferred.
raw docstring

let-flowcljmacro

(let-flow bindings & body)

A version of let where deferred values that are let-bound or closed over can be treated as if they are realized values. The body will only be executed once all of the let-bound values, even ones only used for side effects, have been computed.

Returns a deferred value, representing the value returned by the body.

(let-flow [x (future 1)] (+ x 1))

(let-flow [x (future 1) y (future (+ x 1))] (+ y 1))

(let [x (future 1)] (let-flow [y (future (+ x 1))] (+ y 1)))

A version of `let` where deferred values that are let-bound or closed over can be treated
as if they are realized values.  The body will only be executed once all of the let-bound
values, even ones only used for side effects, have been computed.

Returns a deferred value, representing the value returned by the body.

   (let-flow [x (future 1)]
     (+ x 1))

   (let-flow [x (future 1)
              y (future (+ x 1))]
     (+ y 1))

   (let [x (future 1)]
     (let-flow [y (future (+ x 1))]
       (+ y 1)))
raw docstring

let-flow'cljmacro

(let-flow' bindings & body)

Like let-flow, but only for Manifold deferreds.

Like `let-flow`, but only for Manifold deferreds.
raw docstring

listenerclj

(listener on-success)
(listener on-success on-error)

Creates a listener which can be registered or cancelled via add-listener! and cancel-listener!.

Creates a listener which can be registered or cancelled via `add-listener!` and `cancel-listener!`.
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 (zero? %) % (recur (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 (zero? %)
        %
        (recur (dec %)))))
raw docstring

on-realizedclj

(on-realized x on-success on-error)

Registers callbacks with the manifold deferred for both success and error outcomes.

Registers callbacks with the manifold deferred for both success and error outcomes.
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

realized?clj

(realized? x)

Returns true if the manifold deferred is realized.

Returns true if the manifold deferred is realized.
raw docstring

recurclj

(recur & args)

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

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

success!clj

(success! deferred x)
(success! deferred x claim-token)

Equivalent to deliver, but allows a claim-token to be passed in.

Equivalent to `deliver`, but allows a `claim-token` to be passed in.
raw docstring

success-deferredclj

(success-deferred val)
(success-deferred val executor)

A deferred which already contains a realized value

A deferred which already contains a realized value
raw docstring

timeout!clj

(timeout! d interval)
(timeout! d interval timeout-value)

Takes a deferred, and sets a timeout on it, such that it will be realized as timeout-value (or a TimeoutException if none is specified) if it is not realized in interval ms. Returns the deferred that was passed in.

This will act directly on the deferred value passed in. If the deferred represents a value returned by chain, all actions not yet completed will be short-circuited upon timeout.

Takes a deferred, and sets a timeout on it, such that it will be realized as `timeout-value`
(or a TimeoutException if none is specified) if it is not realized in `interval` ms.  Returns
the deferred that was passed in.

This will act directly on the deferred value passed in.  If the deferred represents a value
returned by `chain`, all actions not yet completed will be short-circuited upon timeout.
raw docstring

unwrapclj

(unwrap x)

unwrap'clj

(unwrap' x)

zipclj

(zip & vals)

Takes a list of values, some of which may be deferrable, and returns a deferred that will yield a list of realized values.

 @(zip 1 2 3) => [1 2 3]
 @(zip (future 1) 2 3) => [1 2 3]
Takes a list of values, some of which may be deferrable, and returns a deferred that will yield a list
of realized values.

     @(zip 1 2 3) => [1 2 3]
     @(zip (future 1) 2 3) => [1 2 3]

raw docstring

zip'clj

(zip' & vals)

Like zip, but only unwraps Manifold deferreds.

Like `zip`, but only unwraps Manifold deferreds.
raw docstring

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

× close