Liking cljdoc? Tell your friends :D

promesa.core


->clj/smacro

(-> x & forms)

Like the clojure.core/->, but it will handle promises in values and make sure the next form gets the value realized instead of the promise.

Example fetching data in the browser with CLJS:

(p/-> (js/fetch #js {...}) ; returns a promise .-body)

The result of a thread is a promise that will resolve to the end of the thread chain.

Like the clojure.core/->, but it will handle promises in values
and make sure the next form gets the value realized instead of
the promise.

Example fetching data in the browser with CLJS:

(p/-> (js/fetch #js {...}) ; returns a promise
      .-body)

The result of a thread is a promise that will resolve to the
end of the thread chain.
sourceraw docstring

->>clj/smacro

(->> x & forms)

Like the clojure.core/->>, but it will handle promises in values and make sure the next form gets the value realized instead of the promise.

Example fetching data in the browser with CLJS:

(p/->> (js/fetch #js {...}) ; returns a promise .-body read-string (mapv inc)

The result of a thread is a promise that will resolve to the end of the thread chain.

Like the clojure.core/->>, but it will handle promises in values
and make sure the next form gets the value realized instead of
the promise.

Example fetching data in the browser with CLJS:

(p/->> (js/fetch #js {...}) ; returns a promise
       .-body
       read-string
       (mapv inc)

The result of a thread is a promise that will resolve to the
end of the thread chain.
sourceraw docstring

allclj/s

(all promises)

Given an array of promises, return a promise that is fulfilled when all the items in the array are fulfilled.

Example:

(-> (p/all [(promise :first-promise)
            (promise :second-promise)])
    (then (fn [[first-result second-result]])
            (println (str first-result ", " second-result))))

Will print to out :first-promise, :second-promise.

If at least one of the promises is rejected, the resulting promise will be rejected.

Given an array of promises, return a promise that is fulfilled when
all the items in the array are fulfilled.

Example:

```
(-> (p/all [(promise :first-promise)
            (promise :second-promise)])
    (then (fn [[first-result second-result]])
            (println (str first-result ", " second-result))))
```

Will print to out `:first-promise, :second-promise`.

If at least one of the promises is rejected, the resulting promise
will be rejected.
sourceraw docstring

anyclj/s

(any promises)
(any promises default)

Given an array of promises, return a promise that is fulfilled when first one item in the array is fulfilled.

Given an array of promises, return a promise that is fulfilled when
first one item in the array is fulfilled.
sourceraw docstring

as->clj/smacro

(as-> expr name & forms)

Like clojure.core/as->, but it will handle promises in values and make sure the next form gets the value realized instead of the promise.

Like clojure.core/as->, but it will handle promises in values
and make sure the next form gets the value realized instead of
the promise.
sourceraw docstring

awaitclj

(await resource)
(await resource duration)

A exception safer variant of await!. Returns nil on timeout exception, forwards interrupted exception and all other exceptions are returned as value, so user is responsible for checking if the returned value is exception or not.

A exception safer variant of `await!`. Returns `nil` on timeout
exception, forwards interrupted exception and all other exceptions
are returned as value, so user is responsible for checking if the returned
value is exception or not.
sourceraw docstring

await!clj

(await! resource)
(await! resource duration)

Generic await operation. Block current thread until some operation terminates. Returns nil on timeout; does not catch any other exception.

Default implementation for Thread, CompletableFuture and CountDownLatch.

The return value is implementation specific.

Generic await operation. Block current thread until some operation
terminates. Returns `nil` on timeout; does not catch any other
exception.

Default implementation for Thread, CompletableFuture and
CountDownLatch.

The return value is implementation specific.
sourceraw docstring

bindclj/s

(bind p f)
(bind p f executor)

Chains a function f to be executed with when the promise p is successfully resolved. Returns a promise that will mirror the promise instance returned by calling f with the value as single argument; f must return a promise instance.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

Chains a function `f` to be executed with when the promise `p` is
successfully resolved. Returns a promise that will mirror the
promise instance returned by calling `f` with the value as single
argument; `f` **must** return a promise instance.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.
sourceraw docstring

cancel!clj/s

(cancel! p)

Cancel the promise.

Cancel the promise.
sourceraw docstring

cancelled?clj/s

(cancelled? v)

Return true if v is a cancelled promise.

Return true if `v` is a cancelled promise.
sourceraw docstring

catchclj/s

(catch p f)
(catch p pred-or-type f)

Chains a function f to be executed when the promise p is rejected. Returns a promise that will be resolved with the return value of calling f with exception as single argument; f can return a plain value or promise instance, an automatic unwrapping will be performed.

The computation will be executed in the completion thread, look at merr if you want the ability to schedule the computation to other thread.

Chains a function `f` to be executed when the promise `p` is
rejected. Returns a promise that will be resolved with the return
value of calling `f` with exception as single argument; `f` can
return a plain value or promise instance, an automatic unwrapping
will be performed.

The computation will be executed in the completion thread, look at
`merr` if you want the ability to schedule the computation to other
thread.
sourceraw docstring

chainclj/s

(chain p f)
(chain p f & fs)

Chain variable number of functions to be executed serially using then.

Chain variable number of functions to be executed serially using
`then`.
sourceraw docstring

chain'clj/s

(chain' p f)
(chain' p f & fs)

Chain variable number of functions to be executed serially using map.

Chain variable number of functions to be executed serially using
`map`.
sourceraw docstring

createclj/s

(create f)
(create f executor)

Create a promise instance from a factory function. If an executor is provided, the factory will be executed in the provided executor.

A factory function looks like (fn [resolve reject] (resolve 1)).

Create a promise instance from a factory function. If an executor is
provided, the factory will be executed in the provided executor.

A factory function looks like `(fn [resolve reject] (resolve 1))`.
sourceraw docstring

deferredclj/s

(deferred)

Creates an empty promise instance.

Creates an empty promise instance.
sourceraw docstring

deferred?clj/s

(deferred? v)

Return true if v is a deferred instance.

Return true if `v` is a deferred instance.
sourceraw docstring

delayclj/s

(delay t)
(delay t v)
(delay t v scheduler)

Given a timeout in miliseconds and optional value, returns a promise that will be fulfilled with provided value (or nil) after the time is reached.

Given a timeout in miliseconds and optional value, returns a promise
that will be fulfilled with provided value (or nil) after the time is
reached.
sourceraw docstring

doclj/smacro

(do & exprs)

Execute potentially side effectful code and return a promise resolved to the last expression after awaiting the result of each expression.

Execute potentially side effectful code and return a promise resolved
to the last expression after awaiting the result of each
expression.
sourceraw docstring

do!clj/smacro

(do! & exprs)

A convenience alias for do macro.

A convenience alias for `do` macro.
sourceraw docstring

do*clj/smacro

(do* & exprs)

An exception unsafe do-like macro. Supposes that we are already wrapped in promise context so avoids defensive wrapping.

An exception unsafe do-like macro. Supposes that we are already
wrapped in promise context so avoids defensive wrapping.
sourceraw docstring

done?clj/s

(done? p)

Returns true if promise p is already done.

Returns true if promise `p` is already done.
sourceraw docstring

doseqclj/smacro

(doseq [binding xs] & body)

Simplified version of doseq which takes one binding and a seq, and runs over it using promesa.core/run!

Simplified version of `doseq` which takes one binding and a seq, and
runs over it using `promesa.core/run!`
sourceraw docstring

errorclj/s

(error f p)
(error f type p)

Same as catch but with parameters inverted.

DEPRECATED

Same as `catch` but with parameters inverted.

DEPRECATED
sourceraw docstring

extractclj/s

(extract p)
(extract p default)

Returns the current promise value.

Returns the current promise value.
sourceraw docstring

finallyclj/s

(finally p f)
(finally p f executor)

Like handle but ignores the return value. Returns a promise that will mirror the original one.

Like `handle` but ignores the return value. Returns a promise that
will mirror the original one.
sourceraw docstring

fmapclj/s

(fmap f p)
(fmap executor f p)

A convenience alias for map.

A convenience alias for `map`.
sourceraw docstring

fnlyclj/s

(fnly f p)
(fnly executor f p)

Inverted arguments version of finally; intended to be used with ->>.

Inverted arguments version of `finally`; intended to be used with
`->>`.
sourceraw docstring

futureclj/smacro

(future & body)

Analogous macro to clojure.core/future that returns promise instance instead of the Future. Exposed just for convenience and works as an alias to thread.

Analogous macro to `clojure.core/future` that returns promise
instance instead of the `Future`. Exposed just for convenience and
works as an alias to `thread`.
sourceraw docstring

handleclj/s

(handle p f)
(handle p f executor)

Chains a function f to be executed when the promise p is completed (resolved or rejected) and returns a promise completed (resolving or rejecting) with the return value of calling f with both: value and the exception; f can return a new plain value or promise instance, and automatic unwrapping will be performed.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

For performance sensitive code, look at hmap and hcat.

Chains a function `f` to be executed when the promise `p` is completed
(resolved or rejected) and returns a promise completed (resolving or
rejecting) with the return value of calling `f` with both: value and
the exception; `f` can return a new plain value or promise instance,
and automatic unwrapping will be performed.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.

For performance sensitive code, look at `hmap` and `hcat`.
sourceraw docstring

hcatclj/s

(hcat f p)
(hcat executor f p)

Chains a function f to be executed when the promise p is completed (resolved or rejected) and returns a promise that will mirror the promise instance returned by calling f with both: value and the exception. The f function must return a promise instance.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

Intended to be used with ->>.

Chains a function `f` to be executed when the promise `p` is completed
(resolved or rejected) and returns a promise that will mirror the
promise instance returned by calling `f` with both: value and the
exception. The `f` function must return a promise instance.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.

Intended to be used with `->>`.
sourceraw docstring

hmapclj/s

(hmap f p)
(hmap executor f p)

Chains a function f to be executed when the promise p is completed (resolved or rejected) and returns a promise completed (resolving or rejecting) with the return value of calling f with both: value and the exception.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

Intended to be used with ->>.

Chains a function `f` to be executed when the promise `p` is completed
(resolved or rejected) and returns a promise completed (resolving or
rejecting) with the return value of calling `f` with both: value and
the exception.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.

Intended to be used with `->>`.
sourceraw docstring

letclj/smacro

(let bindings & body)

A let alternative that always returns promise and waits for all the promises on the bindings.

A `let` alternative that always returns promise and waits for all the
promises on the bindings.
sourceraw docstring

let*clj/smacro

(let* bindings & body)

An exception unsafe let-like macro. Supposes that we are already wrapped in promise context so avoids defensive wrapping.

An exception unsafe let-like macro. Supposes that we are already
wrapped in promise context so avoids defensive wrapping.
sourceraw docstring

loopclj/smacro

(loop bindings & body)
source

mapclj/s

(map f p)
(map executor f p)

Chains a function f to be executed when the promise p is successfully resolved. Returns a promise that will be resolved with the return value of calling f with value as single argument.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

This function is intended to be used with ->>.

Chains a function `f` to be executed when the promise `p` is
successfully resolved. Returns a promise that will be resolved with
the return value of calling `f` with value as single argument.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.

This function is intended to be used with `->>`.
sourceraw docstring

mapcatclj/s

(mapcat f p)
(mapcat executor f p)

Chains a function f to be executed when the promise p is successfully resolved. Returns a promise that will mirror the promise instance returned by calling f with the value as single argument; f must return a promise instance.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

This funciton is intended to be used with ->>.

Chains a function `f` to be executed when the promise `p` is
successfully resolved. Returns a promise that will mirror the
promise instance returned by calling `f` with the value as single
argument; `f` **must** return a promise instance.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.

This funciton is intended to be used with `->>`.
sourceraw docstring

mcatclj/s

(mcat f p)
(mcat executor f p)

A convenience alias for mapcat.

A convenience alias for `mapcat`.
sourceraw docstring

merrclj/s

(merr f p)
(merr executor f p)

Chains a function f to be executed when the promise p is rejected. Returns a promise that will mirror the promise returned by calling f with exception as single argument; f must return a promise instance or throw an exception.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

This is intended to be used with ->>.

Chains a function `f` to be executed when the promise `p` is
rejected. Returns a promise that will mirror the promise returned by
calling `f` with exception as single argument; `f` **must** return a
promise instance or throw an exception.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.

This is intended to be used with `->>`.
sourceraw docstring

pending?clj/s

(pending? p)

Returns true if promise p is stil pending.

Returns true if promise `p` is stil pending.
sourceraw docstring

pletclj/smacro

(plet bindings & body)

A parallel let; executes all the bindings in parallel and when all bindings are resolved, executes the body.

A parallel let; executes all the bindings in parallel and when all
bindings are resolved, executes the body.
sourceraw docstring

promiseclj/s

(promise v)
(promise v executor)

The coerce based promise constructor. Creates an appropriate promise instance depending on the provided value.

If an executor is provided, it will be used to resolve this promise.

The coerce based promise constructor. Creates an appropriate promise
instance depending on the provided value.

If an executor is provided, it will be used to resolve this
promise.
sourceraw docstring

promise?clj/s

(promise? v)

Return true if v is a promise instance.

Return true if `v` is a promise instance.
sourceraw docstring

promisifyclj/s

(promisify callable)

Given a function that accepts a callback as the last argument, return a function that returns a promise. Callback is expected to take one parameter (result of a computation).

Given a function that accepts a callback as the last argument, return a
function that returns a promise. Callback is expected to take one
parameter (result of a computation).
sourceraw docstring

raceclj/s

(race promises)
source

recurclj/smacro

(recur & args)
source

recur?clj/s

(recur? o)
source

reject!clj/s

(reject! p e)

Reject a completable promise with an error.

Reject a completable promise with an error.
sourceraw docstring

rejectedclj/s

(rejected v)

Return a rejected promise with provided reason.

Return a rejected promise with provided reason.
sourceraw docstring

rejected?clj/s

(rejected? p)

Returns true if promise p is already rejected.

Returns true if promise `p` is already rejected.
sourceraw docstring

resolve!clj/s

(resolve! o)
(resolve! o v)

Resolve a completable promise with a value.

Resolve a completable promise with a value.
sourceraw docstring

resolvedclj/s

(resolved v)

Return a resolved promise with provided value.

Return a resolved promise with provided value.
sourceraw docstring

resolved?clj/s

(resolved? p)

Returns true if promise p is already fulfilled.

Returns true if promise `p` is already fulfilled.
sourceraw docstring

run!clj/s

(run! f coll)
(run! f coll executor)

A promise aware run! function. Executed in terms of then rules.

A promise aware run! function. Executed in terms of `then` rules.
sourceraw docstring

thenclj/s

(then p f)
(then p f executor)

Chains a function f to be executed when the promise p is successfully resolved. Returns a promise that will be resolved with the return value of calling f with value as single argument; f can return a plain value or promise instance, an automatic unwrapping will be performed.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

Chains a function `f` to be executed when the promise `p` is
successfully resolved. Returns a promise that will be resolved with
the return value of calling `f` with value as single argument; `f`
can return a plain value or promise instance, an automatic
unwrapping will be performed.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.
sourceraw docstring

then'clj/s

(then' p f)
(then' p f executor)

Chains a function f to be executed when the promise p is successfully resolved. Returns a promise that will be resolved with the return value of calling f with value as single argument; f should return a plain value, no automatic unwrapping will be performed.

The computation will be executed in the completion thread by default; you also can provide a custom executor.

Chains a function `f` to be executed when the promise `p` is
successfully resolved. Returns a promise that will be resolved with
the return value of calling `f` with value as single argument; `f`
should return a plain value, no automatic unwrapping will be
performed.

The computation will be executed in the completion thread by
default; you also can provide a custom executor.
sourceraw docstring

thenable?cljs

(thenable? v)

Returns true if v is a promise like object.

Returns true if `v` is a promise like object.
sourceraw docstring

threadclj/smacro

(thread & body)

Analogous to clojure.core.async/thread that returns a promise instance instead of the Future.

Analogous to `clojure.core.async/thread` that returns a promise instance
instead of the `Future`.
sourceraw docstring

thread-callclj/s

(thread-call f)
(thread-call executor f)

Analogous to clojure.core.async/thread that returns a promise instance instead of the Future. Useful for executing synchronous code in a separate thread (also works in cljs).

Analogous to `clojure.core.async/thread` that returns a promise
instance instead of the `Future`. Useful for executing synchronous
code in a separate thread (also works in cljs).
sourceraw docstring

timeoutclj/s

(timeout p t)
(timeout p t v)
(timeout p t v scheduler)

Returns a cancellable promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within ms milliseconds, the returned promise is cancelled with a TimeoutError.

Returns a cancellable promise that will be fulfilled with this
promise's fulfillment value or rejection reason.  However, if this
promise is not fulfilled or rejected within `ms` milliseconds, the
returned promise is cancelled with a TimeoutError.
sourceraw docstring

TimeoutExceptioncljs

(TimeoutException message)
source

vthreadclj/smacro

(vthread & body)

Analogous to clojure.core.async/thread that returns a promise instance instead of the Future. Useful for executing synchronous code in a separate thread (also works in cljs).

Analogous to `clojure.core.async/thread` that returns a promise instance
instead of the `Future`. Useful for executing synchronous code in a
separate thread (also works in cljs).
sourceraw docstring

vthread-callclj/s

(vthread-call f)

A shortcut for (p/thread-call :vthread f).

A shortcut for `(p/thread-call :vthread f)`.
sourceraw docstring

wait-allclj/s

(wait-all & promises)

Given a variable number of promises, returns a promise which resolves to nil when all provided promises complete (rejected or resolved).

EXPERIMENTAL

Given a variable number of promises, returns a promise which resolves
to `nil` when all provided promises complete (rejected or resolved).

**EXPERIMENTAL**
sourceraw docstring

wait-all!clj

(wait-all! promises)

A blocking version of wait-all.

A blocking version of `wait-all`.
sourceraw docstring

wait-all*clj/s

(wait-all* promises)

Given an array of promises, return a promise that is fulfilled when all the items in the array are resolved (independently if successfully or exceptionally).

Example:

(->> (p/wait-all* [(promise :first-promise)
                   (promise :second-promise)])
     (p/fmap (fn [_]
               (println "done"))))

Rejected promises also counts as resolved.

Given an array of promises, return a promise that is fulfilled when
all the items in the array are resolved (independently if
successfully or exceptionally).

Example:

```
(->> (p/wait-all* [(promise :first-promise)
                   (promise :second-promise)])
     (p/fmap (fn [_]
               (println "done"))))
```

Rejected promises also counts as resolved.
sourceraw docstring

with-redefsclj/smacro

(with-redefs bindings & body)

Like clojure.core/with-redefs, but it will handle promises in body and wait until they resolve or reject before restoring the bindings. Useful for mocking async APIs.

Like clojure.core/with-redefs, but it will handle promises in
body and wait until they resolve or reject before restoring the
bindings. Useful for mocking async APIs.
sourceraw docstring

wrapclj/s

(wrap v)

A convenience alias for promise coercion function that only accepts a single argument.

A convenience alias for `promise` coercion function that only accepts
a single argument.
sourceraw docstring

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

× close