Bridges promises and channels, in both directions, with the error
propagation of jtk-dvlp.async.
A rejected promise arrives on the channel as a carried error and is
thrown by <!; an error carried on a channel rejects the promise it
is turned into. So a .then/.catch chain and a go block stack can
be mixed without either side losing an error.
WATCHOUT: promise means different things on the two platforms. In
ClojureScript it is a js/Promise with then and catch. On the
JVM it is a clojure.core/promise, which has neither and only takes
a single deliver — there is no rejection there, only a delivered
exception value. The functions here even that out; where it still
shows through, it is said so.
Bridges promises and channels, in both directions, with the error propagation of `jtk-dvlp.async`. A rejected promise arrives on the channel as a carried error and is thrown by `<!`; an error carried on a channel rejects the promise it is turned into. So a `.then`/`.catch` chain and a go block stack can be mixed without either side losing an error. WATCHOUT: `promise` means different things on the two platforms. In ClojureScript it is a `js/Promise` with `then` and `catch`. On the JVM it is a `clojure.core/promise`, which has neither and only takes a single `deliver` — there is no rejection there, only a delivered exception value. The functions here even that out; where it still shows through, it is said so.
(->promise-chan c)Ensures channel c behaves like a promise-chan: its first value
is kept and handed out on every take, instead of being gone after
the first one. Closes c afterwards.
For a result several readers need, or one that is read more than once.
Ensures channel `c` behaves like a `promise-chan`: its first value is kept and handed out on every take, instead of being gone after the first one. Closes `c` afterwards. For a result several readers need, or one that is read more than once.
(<p! ?exp)Like jtk-dvlp.async/<!, but for a promise: takes its value, or
throws if it was rejected. Shorthand for (<! (p->c ?exp)).
Like `jtk-dvlp.async/<!`, but for a promise: takes its value, or throws if it was rejected. Shorthand for `(<! (p->c ?exp))`.
(<p!! ?exp)Like jtk-dvlp.async/<!!, but for a promise. Blocks the calling
thread.
Clojure only — ClojureScript has no blocking take.
Like `jtk-dvlp.async/<!!`, but for a promise. Blocks the calling thread. Clojure only — ClojureScript has no blocking take.
(c->p c)Turns channel c into a promise: resolved with the channel's value,
rejected with it if it is a carried error. Closes c afterwards.
The counterpart of p->c, for handing a channel to code that
expects a promise.
Turns channel `c` into a promise: resolved with the channel's value, rejected with it if it is a carried error. Closes `c` afterwards. The counterpart of `p->c`, for handing a channel to code that expects a promise.
(p->c p)Turns promise p into a promise-chan carrying its value, or its
error if the promise is rejected. A rejection that is an exception
travels as itself; anything else — a promise may reject with any
value at all — is lifted into an ExceptionInfo with
{:code :promise-error} and the value under :error.
WATCHOUT: The channel is closed once the value is on it, but it is a
promise-chan — it hands out its buffered value on every take, also
when closed. Closed here means "takes nothing new", not "yields
nothing more".
Turns promise `p` into a `promise-chan` carrying its value, or its
error if the promise is rejected. A rejection that is an exception
travels as itself; anything else — a promise may reject with any
value at all — is lifted into an `ExceptionInfo` with
`{:code :promise-error}` and the value under `:error`.
WATCHOUT: The channel is closed once the value is on it, but it is a
`promise-chan` — it hands out its buffered value on every take, also
when closed. Closed here means "takes nothing new", not "yields
nothing more".(promise-chan)(promise-chan f)Creates a promise-chan — a channel that keeps its first value and
hands it out on every take. See core.async/promise-chan.
Without arguments it is just that, empty. Given f, it is called
with two one-argument functions, resolve and reject, to fill the
channel — the same shape as a JavaScript promise executor. A
rejection that is an exception travels as itself; anything else is
lifted into an ExceptionInfo.
Creates a `promise-chan` — a channel that keeps its first value and hands it out on every take. See `core.async/promise-chan`. Without arguments it is just that, empty. Given `f`, it is called with two one-argument functions, `resolve` and `reject`, to fill the channel — the same shape as a JavaScript promise executor. A rejection that is an exception travels as itself; anything else is lifted into an `ExceptionInfo`.
(promise-go & body)Like jtk-dvlp.async/go, but yields a promise-chan: the result
can be taken more than once, instead of being gone after the
first take.
Like `jtk-dvlp.async/go`, but yields a `promise-chan`: the result can be taken more than once, instead of being gone after the first take.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |