Liking cljdoc? Tell your friends :D

jtk-dvlp.async.interop.callback

Turns callback-based functions into channels, with the error propagation of jtk-dvlp.async.

A callback API does not fit into a sequence of steps: the rest of the work has to move inside the callback, and every further call nests one level deeper. cb->c turns such a call into a channel, so it reads like any other step in a go block — and a failure arrives as a thrown error rather than as a second callback.

WATCHOUT: cb->c is a macro that rewrites the expression handed to it. It looks for the symbols callback, resolve and reject inside and puts its own functions in their place. Those symbols are therefore written bare, without ever being defined — and they are only found where they literally stand. Move a callback into a helper function and the macro cannot see it any more.

Turns callback-based functions into channels, with the error
propagation of `jtk-dvlp.async`.

A callback API does not fit into a sequence of steps: the rest of
the work has to move inside the callback, and every further call
nests one level deeper. `cb->c` turns such a call into a channel, so
it reads like any other step in a go block — and a failure arrives
as a thrown error rather than as a second callback.

WATCHOUT: `cb->c` is a macro that *rewrites* the expression handed
to it. It looks for the symbols `callback`, `resolve` and `reject`
inside and puts its own functions in their place. Those symbols are
therefore written bare, without ever being defined — and they are
only found where they literally stand. Move a callback into a helper
function and the macro cannot see it any more.
raw docstring

jtk-dvlp.async.interop.promise

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.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close