|
10 | 10 | [manifold.time :as time]
|
11 | 11 | [manifold.utils :as utils :refer [assert-some definterface+]]
|
12 | 12 | [potemkin.types :refer [def-abstract-type reify+ defprotocol+ deftype+]]
|
| 13 | + [clj-commons.primitive-math :as p] |
13 | 14 | [riddley.compiler :as compiler]
|
14 | 15 | [riddley.walk :as walk])
|
15 | 16 | (:import
|
|
689 | 690 | ([]
|
690 | 691 | (deferred (ex/executor)))
|
691 | 692 | ([executor]
|
692 |
| - (if (and (zero? (rem (.incrementAndGet created) 1024)) |
| 693 | + (if (and (p/zero? (rem (.incrementAndGet created) 1024)) |
693 | 694 | debug/*dropped-error-logging-enabled?*)
|
694 | 695 | (LeakAwareDeferred. nil ::unset nil (utils/mutex) (LinkedList.) nil false executor)
|
695 | 696 | (Deferred. nil ::unset nil (utils/mutex) (LinkedList.) nil false executor)))))
|
|
703 | 704 | #_{:inline
|
704 | 705 | (fn [val]
|
705 | 706 | (cond
|
706 |
| - (true? val) 'manifold.deferred/true-deferred- |
707 |
| - (false? val) 'manifold.deferred/false-deferred- |
| 707 | + (p/true? val) 'manifold.deferred/true-deferred- |
| 708 | + (p/false? val) 'manifold.deferred/false-deferred- |
708 | 709 | (nil? val) 'manifold.deferred/nil-deferred-
|
709 | 710 | :else `(SuccessDeferred. ~val nil nil)))
|
710 | 711 | :inline-arities #{1}}
|
|
1026 | 1027 | "Like `chain`, but does not coerce deferrable values. This is useful both when coercion
|
1027 | 1028 | is undesired, or for 2-4x better performance than `chain`."
|
1028 | 1029 | {:inline (fn [& args]
|
1029 |
| - (if false #_(< 3 (count args)) |
| 1030 | + (if false #_(p/< 3 (count args)) |
1030 | 1031 | (apply unroll-chain 'manifold.deferred/unwrap' args)
|
1031 | 1032 | `(chain'- nil ~@args)))}
|
1032 | 1033 | ([x]
|
|
1046 | 1047 | The returned deferred will only be realized once all functions have been applied and their
|
1047 | 1048 | return values realized.
|
1048 | 1049 |
|
1049 |
| - @(chain 1 inc #(future (inc %))) => 3 |
| 1050 | + @(chain 1 inc #(future (p/inc %))) => 3 |
1050 | 1051 |
|
1051 | 1052 | @(chain (future 1) inc inc) => 3
|
1052 | 1053 | "
|
1053 | 1054 | {:inline (fn [& args]
|
1054 |
| - (if false #_(< 3 (count args)) |
| 1055 | + (if false #_(p/< 3 (count args)) |
1055 | 1056 | (apply unroll-chain 'manifold.deferred/unwrap args)
|
1056 | 1057 | `(chain- nil ~@args)))}
|
1057 | 1058 | ([x]
|
|
1153 | 1154 | (defn finally
|
1154 | 1155 | "An equivalent of the finally clause, which takes a no-arg side-effecting function that executes
|
1155 | 1156 | no matter what the result.
|
1156 |
| - |
| 1157 | +
|
1157 | 1158 | Returns x unless a Throwable is thrown in f, in which case it returns an error-deferred."
|
1158 | 1159 | [x f]
|
1159 | 1160 | (if-let [d (->deferred x nil)]
|
|
1174 | 1175 |
|
1175 | 1176 | ;; no further results, decrement the counter one last time
|
1176 | 1177 | ;; and return the result if everything else has been realized
|
1177 |
| - (if (zero? (.get counter)) |
| 1178 | + (if (p/zero? (.get counter)) |
1178 | 1179 | (success-deferred (or (seq ary) (list)))
|
1179 | 1180 | d)
|
1180 | 1181 |
|
|
1196 | 1197 | (on-realized (chain' x)
|
1197 | 1198 | (fn [val]
|
1198 | 1199 | (aset ary idx val)
|
1199 |
| - (when (zero? (.decrementAndGet counter)) |
| 1200 | + (when (p/zero? (.decrementAndGet counter)) |
1200 | 1201 | (success! d (seq ary))))
|
1201 | 1202 | (fn [err]
|
1202 | 1203 | (error! d err)))
|
|
1228 | 1229 | (clojure.core/loop [i 1]
|
1229 | 1230 | (if (= i n)
|
1230 | 1231 | a
|
1231 |
| - (let [j (rand-int (inc i))] |
| 1232 | + (let [j (rand-int (p/inc i))] |
1232 | 1233 | (aset a i (aget a j))
|
1233 | 1234 | (aset a j i)
|
1234 |
| - (recur (inc i))))))) |
| 1235 | + (recur (p/inc i))))))) |
1235 | 1236 |
|
1236 | 1237 | (defn alt'
|
1237 | 1238 | "Like `alt`, but only unwraps Manifold deferreds."
|
|
1240 | 1241 | cnt (count vals)
|
1241 | 1242 | ^ints idxs (random-array cnt)]
|
1242 | 1243 | (clojure.core/loop [i 0]
|
1243 |
| - (when (< i cnt) |
| 1244 | + (when (p/< i cnt) |
1244 | 1245 | (let [i' (aget idxs i)
|
1245 | 1246 | x (nth vals i')]
|
1246 | 1247 | (if (deferred? x)
|
|
1250 | 1251 | (do (on-realized (chain' x)
|
1251 | 1252 | #(success! d %)
|
1252 | 1253 | #(error! d %))
|
1253 |
| - (recur (inc i)))) |
| 1254 | + (recur (p/inc i)))) |
1254 | 1255 | (success! d x)))))
|
1255 | 1256 | d))
|
1256 | 1257 |
|
|
1324 | 1325 |
|
1325 | 1326 | (loop [i 1e6]
|
1326 | 1327 | (chain (future i)
|
1327 |
| - #(if (zero? %) |
| 1328 | + #(if (p/zero? %) |
1328 | 1329 | %
|
1329 |
| - (recur (dec %)))))" |
| 1330 | + (recur (p/dec %)))))" |
1330 | 1331 | [bindings & body]
|
1331 | 1332 | (let [vars (->> bindings (partition 2) (map first))
|
1332 | 1333 | vals (->> bindings (partition 2) (map second))
|
|
1479 | 1480 | Returns a deferred value, representing the value returned by the body.
|
1480 | 1481 |
|
1481 | 1482 | (let-flow [x (future 1)]
|
1482 |
| - (+ x 1)) |
| 1483 | + (p/+ x 1)) |
1483 | 1484 |
|
1484 | 1485 | (let-flow [x (future 1)
|
1485 |
| - y (future (+ x 1))] |
1486 |
| - (+ y 1)) |
| 1486 | + y (future (p/+ x 1))] |
| 1487 | + (p/+ y 1)) |
1487 | 1488 |
|
1488 | 1489 | (let [x (future 1)]
|
1489 |
| - (let-flow [y (future (+ x 1))] |
1490 |
| - (+ y 1)))" |
| 1490 | + (let-flow [y (future (p/+ x 1))] |
| 1491 | + (p/+ y 1)))" |
1491 | 1492 | [bindings & body]
|
1492 | 1493 | (expand-let-flow
|
1493 | 1494 | 'manifold.deferred/chain
|
|
0 commit comments