Liking cljdoc? Tell your friends :D

sci.impl.async-macro

Transforms async function bodies with await into Promise .then chains.

Supports await in:

  • let bindings: (let [x (await p)] ...)
  • do forms: (do (await p) ...)
  • arbitrary expressions: (inc (await p))
  • macros like -> are expanded first

Example: (defn ^:async foo [] (let [x (await (js/Promise.resolve 1))] (inc x)))

Transforms to: (defn foo [] (.then (js/Promise.resolve 1) (fn [x] (inc x))))

Transforms async function bodies with await into Promise .then chains.

Supports await in:
- let bindings: (let [x (await p)] ...)
- do forms: (do (await p) ...)
- arbitrary expressions: (inc (await p))
- macros like -> are expanded first

Example:
  (defn ^:async foo []
    (let [x (await (js/Promise.resolve 1))]
      (inc x)))

Transforms to:
  (defn foo []
    (.then (js/Promise.resolve 1) (fn [x] (inc x))))
raw docstring

mark-promiseclj/s

(mark-promise form)

Mark a form as promise-producing using metadata.

Mark a form as promise-producing using metadata.
sourceraw docstring

promise-catchclj/s

(promise-catch promise-expr callback)

Create a .catch chain

Create a .catch chain
sourceraw docstring

promise-catch-for-tryclj/s

(promise-catch-for-try promise-expr callback)

Create a .catch chain that unwraps SCI error wrapping before calling handler

Create a .catch chain that unwraps SCI error wrapping before calling handler
sourceraw docstring

promise-finallyclj/s

(promise-finally promise-expr callback)

Create a .finally chain

Create a .finally chain
sourceraw docstring

promise-thenclj/s

(promise-then promise-expr callback)

Create a .then chain

Create a .then chain
sourceraw docstring

transform-async-bodyclj/s

(transform-async-body ctx locals body)

Walk body and transform await calls. Expands macros first if needed. locals is a set of locally bound symbols that should not be macro-expanded.

Walk body and transform await calls. Expands macros first if needed.
locals is a set of locally bound symbols that should not be macro-expanded.
sourceraw docstring

transform-async-fn-bodyclj/s

(transform-async-fn-body ctx locals body-exprs)

Transform async function body expressions and ensure result is a promise. This is the main entry point for async function transformation.

Transform async function body expressions and ensure result is a promise.
This is the main entry point for async function transformation.
sourceraw docstring

transform-doclj/s

(transform-do ctx locals exprs)

Transform do with await calls into .then chains.

Transform do with await calls into .then chains.
sourceraw docstring

transform-expr-with-awaitclj/s

(transform-expr-with-await ctx locals expr)

Transform a general expression, chaining any promise-producing subforms.

Transform a general expression, chaining any promise-producing subforms.
sourceraw docstring

transform-let*clj/s

(transform-let* ctx locals bindings body)

Transform let* with await calls into .then chains.

Transform let* with await calls into .then chains.
sourceraw docstring

transform-loop*clj/s

(transform-loop* ctx locals bindings body)

Transform loop* with await into a recursive promise-returning function. Wraps init values in let* to preserve sequential scoping (each init sees previous bindings). Returns original loop unchanged if there are no promises.

(loop* [x 0] (if (< x 3) (do (await p) (recur (inc x))) x)) => (let* [x 0] ((fn loop-fn [x] (if (< x 3) (.then p (fn [_] (loop-fn (inc x)))) (js/Promise.resolve x))) x))

Transform loop* with await into a recursive promise-returning function.
Wraps init values in let* to preserve sequential scoping (each init sees previous bindings).
Returns original loop unchanged if there are no promises.

(loop* [x 0] (if (< x 3) (do (await p) (recur (inc x))) x))
=>
(let* [x 0]
  ((fn loop-fn [x] (if (< x 3) (.then p (fn [_] (loop-fn (inc x)))) (js/Promise.resolve x))) x))
sourceraw docstring

transform-tryclj/s

(transform-try ctx locals exprs)

Transform try/catch/finally with await into Promise .catch/.finally chains. Only uses promise chains if there's actually an await somewhere.

Transform try/catch/finally with await into Promise .catch/.finally chains.
Only uses promise chains if there's actually an await somewhere.
sourceraw docstring

wrap-promiseclj/s

(wrap-promise expr)

Wrap value in promise resolve to handle non-Promise values

Wrap value in promise resolve to handle non-Promise values
sourceraw 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