Skip to content

Commit 775cdfc

Browse files
committed
Update m.deferred docstrings
1 parent 23d41c2 commit 775cdfc

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/manifold/deferred.clj

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -725,15 +725,20 @@
725725

726726
(declare chain)
727727

728-
(defn unwrap' [x]
728+
(defn unwrap'
729+
"Like unwrap, but does not coerce deferrable values."
730+
[x]
729731
(if (deferred? x)
730732
(let [val (success-value x ::none)]
731733
(if (identical? val ::none)
732734
x
733735
(recur val)))
734736
x))
735737

736-
(defn unwrap [x]
738+
(defn unwrap
739+
"Recursively unwraps a deferred or deferrable until either 1) a non-deferred
740+
value is reached, or 2) an unrealized deferrable is reached."
741+
[x]
737742
(let [d (->deferred x nil)]
738743
(if (nil? d)
739744
x
@@ -1041,7 +1046,6 @@
10411046
@(chain 1 inc #(future (inc %))) => 3
10421047
10431048
@(chain (future 1) inc inc) => 3
1044-
10451049
"
10461050
{:inline (fn [& args]
10471051
(if false #_(< 3 (count args))
@@ -1207,7 +1211,6 @@
12071211
12081212
@(zip 1 2 3) => [1 2 3]
12091213
@(zip (future 1) 2 3) => [1 2 3]
1210-
12111214
"
12121215
{:inline (fn [x] `(chain ~x vector))
12131216
:inline-arities #{1}}
@@ -1313,7 +1316,8 @@
13131316

13141317
(defmacro loop
13151318
"A version of Clojure's loop which allows for asynchronous loops, via `manifold.deferred/recur`.
1316-
`loop` will always return a deferred value, even if the body is synchronous. Note that `loop` does **not** coerce values to deferreds, actual Manifold deferreds must be used.
1319+
`loop` will always return a deferred value, even if the body is synchronous. Note that `loop`
1320+
does **not** coerce values to deferreds, actual Manifold deferreds must be used.
13171321
13181322
(loop [i 1e6]
13191323
(chain (future i)
@@ -1497,6 +1501,8 @@
14971501
bindings
14981502
body))
14991503

1504+
1505+
15001506
(defmethod print-method IDeferred [o ^Writer w]
15011507
(.write w
15021508
(str
@@ -1513,9 +1519,14 @@
15131519
(prefer-method print-method IDeferred IDeref)
15141520

15151521

1522+
1523+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1524+
;; CompletionStage helper fns
1525+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1526+
15161527
(defmacro ^:no-doc def-async-for
15171528
"Defines a CompletionStage async version of the function associated with
1518-
the given symbol."
1529+
the given symbol, with '-async' appended."
15191530
[fn-name]
15201531
(let [async-name (symbol (str (name fn-name) "-async"))]
15211532
`(defn- ~async-name
@@ -1526,7 +1537,7 @@
15261537

15271538
(defmacro ^:no-doc def-async-for-dual
15281539
"Defines a CompletionStage async version of the two-deferred
1529-
function associated with the given symbol."
1540+
function associated with the given symbol, with '-async' appended."
15301541
[fn-name]
15311542
(let [async-name (symbol (str (name fn-name) "-async"))]
15321543
`(defn- ~async-name
@@ -1536,17 +1547,19 @@
15361547
(~fn-name (onto d# executor#) d2# f#)))))
15371548

15381549
(defn- fmap-deferred
1539-
"Like map/fmap but for deferreds.
1550+
"Returns a new deferred with function `f` applies to realized value of `d`.
1551+
(Like fmap but for deferreds.)
15401552
1541-
This function does not unwrap the result of f"
1553+
This function does not unwrap the result of f; it will only be applied to
1554+
the immediate value of `d`. This is for mimicking CompletionStage's
1555+
behavior."
15421556
[d f]
15431557
(let [d' (deferred)]
15441558
(on-realized d
15451559
(fn [val] (success! d' (f val)))
15461560
(fn [error] (error! d' error)))
15471561
d'))
15481562

1549-
15501563
(defn- then-apply [d ^Function f]
15511564
(assert-some f)
15521565
(fmap-deferred d #(.apply f %)))

0 commit comments

Comments
 (0)