Core functionality to do asynchronous programming.
Core functionality to do asynchronous programming.
(all promises)
Returns a promise that resolves to a sequence of the results of all the given promises in the same order, or rejects with the first promise in the list that is rejected.
Returns a promise that resolves to a sequence of the results of all the given promises in the same order, or rejects with the first promise in the list that is rejected.
(all-settled promises)
Returns a promise that resolves to a sequence of infos for each
of the given promises, once all of them have settled. Those
informative objects are maps with a :status
entry, and either a
:value
entry for resolved promises, or a :reason
entry for those
that are rejected.
Returns a promise that resolves to a sequence of infos for each of the given promises, once all of them have settled. Those informative objects are maps with a `:status` entry, and either a `:value` entry for resolved promises, or a `:reason` entry for those that are rejected.
(any & promises)
Returns a promise that resolves to the any of the given promises
which resolves successfully. It rejects only if all the given
promises are rejected, in which case the reason will be a
js/AggregateError containing all the rejection reasons. Note
that (any)
will fail immediately.
Returns a promise that resolves to the any of the given promises which resolves successfully. It rejects only if all the given promises are rejected, in which case the reason will be a js/AggregateError containing all the rejection reasons. Note that `(any)` will fail immediately.
(async & body)
Returns a promise executing the code in body
. Inside the
body, async
expressions can be used to wait for and return the
result of other promises. Errors thrown during the execution will
result in a rejected promise.
Example:
(async
(let [r1 (await (some-async-op))]
(or r1 (await (some-other-async-op)))))
Returns a promise executing the code in `body`. Inside the body, [[async]] expressions can be used to wait for and return the result of other promises. Errors thrown during the execution will result in a rejected promise. Example: ```clojure (async (let [r1 (await (some-async-op))] (or r1 (await (some-other-async-op))))) ```
(await promise)
Return the value that the given promise resolves to, or throw the
reason if it is rejected. This can only be used inside an async
expression.
Return the value that the given promise resolves to, or throw the reason if it is rejected. This can only be used inside an [[async]] expression.
(catch p f)
Returns a promise that continues in the function f
once and if
the promise p
is rejected. f
will be called with the reason of
the rejected p
and may return another promise.
Returns a promise that continues in the function `f` once and if the promise `p` is rejected. `f` will be called with the reason of the rejected `p` and may return another promise.
(finally p f)
Returns a promise that calls f
once the promise p
is settled,
no matter if resolved or rejected. f
will be called with no
arguments, and its return value is ignored.
Returns a promise that calls `f` once the promise `p` is settled, no matter if resolved or rejected. `f` will be called with no arguments, and its return value is ignored.
(promise f)
Creates a new promise based on a function f
, which is later
called with two arguments resolve
and reject
. Eventually one of
those functions must be called.
Creates a new promise based on a function `f`, which is later called with two arguments `resolve` and `reject`. Eventually one of those functions must be called.
(promise? v)
Returns whether v is a promise.
Returns whether v is a promise.
(race & promises)
Returns a promise that resolves or rejects to the first promise or
the given promises that does any of that. Note that (race)
will
never resolve nor reject.
Returns a promise that resolves or rejects to the first promise or the given promises that does any of that. Note that `(race)` will never resolve nor reject.
(reject reason)
Returns a promise that is immediately in the rejected state, with
the given reason
value, which is usually an error value.
Returns a promise that is immediately in the rejected state, with the given `reason` value, which is usually an error value.
(resolve v)
Returns a promise that is immediately in the resolved state, with
v
as its result, unless v
is a promise, in which case v
is
returned.
Returns a promise that is immediately in the resolved state, with `v` as its result, unless `v` is a promise, in which case `v` is returned.
(then p f)
(then p f catch-f)
Returns a promise that continues in the function f
once and if
the promise p
is resolved. f
will be called with the result of
p
and may return another promise. When catch-f
is specified, it
is called if p
is rejected.
Returns a promise that continues in the function `f` once and if the promise `p` is resolved. `f` will be called with the result of `p` and may return another promise. When `catch-f` is specified, it is called if `p` is rejected.
(timeout ms & [value])
Returns a promise that resolves after the given number of
milliseconds to the given value, which defaults to nil
.
Returns a promise that resolves after the given number of milliseconds to the given value, which defaults to `nil`.
(try-finally f g)
Calls f
in a try-finally block, eventually calling g
afterwards. Unlike an ordinary try..finally
expression, if f
does not throw and returns a promise, then g
is called after that
promise is settled.
Calls `f` in a try-finally block, eventually calling `g` afterwards. Unlike an ordinary `try..finally` expression, if `f` does not throw and returns a promise, then `g` is called after that promise is settled.
(with-redefs bindings & body)
binding => var-symbol temp-value-expr
Temporarily redefines vars while executing the body. The temp-value-exprs will be evaluated and each resulting value will replace in parallel the root value of its var. After the body is executed, the root values of all the vars will be set back to their old values. Useful for mocking out functions during testing.
This is almost the same as [[clojure.core/with-redefs]], except if
body
evaluates to a promise, the vars will not be set back to
their previous values until that promise settles.
`binding => var-symbol temp-value-expr` Temporarily redefines vars while executing the body. The temp-value-exprs will be evaluated and each resulting value will replace in parallel the root value of its var. After the body is executed, the root values of all the vars will be set back to their old values. Useful for mocking out functions during testing. This is almost the same as [[clojure.core/with-redefs]], except if `body` evaluates to a promise, the vars will not be set back to their previous values until that promise settles.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close