(fire-rules session)
(fire-rules session opts)
Fires :then and :then-finally blocks for any rules whose matches have been updated.
The opts map may contain:
:recursion-limit - Throws an error if rules recursively trigger this many times.
The default is 16. Pass nil to disable the limit entirely.
Source
(defn
fire-rules
"Fires :then and :then-finally blocks for any rules whose matches have been updated.\n The opts map may contain:\n \n :recursion-limit - Throws an error if rules recursively trigger this many times.\n The default is 16. Pass nil to disable the limit entirely."
([session] (fire-rules session {}))
([session opts]
(let
[then-queue
(:then-queue session)
then-finally-queue
(:then-finally-queue session)]
(if
(and
(or (seq then-queue) (seq then-finally-queue))
(nil? *session*))
(let
[*node-id->triggered-node-ids
(volatile! {})
execute-fn
(fn
[f node-id]
(binding
[*triggered-node-ids* (volatile! #{})]
(f)
(vswap!
*node-id->triggered-node-ids
update
node-id
(fn*
[p1__43217#]
(into (or p1__43217# #{}) @*triggered-node-ids*)))))
session
(assoc session :then-queue #{} :then-finally-queue #{})
session
(reduce
(fn
[session node-id]
(update-in session [:beta-nodes node-id] assoc :trigger false))
session
(into then-finally-queue (map first then-queue)))
beta-nodes
(:beta-nodes session)
session
(reduce
(fn
[session [node-id id+attrs]]
(let
[{:keys [matches then-fn]} (get beta-nodes node-id)]
(or
(when-let
[{:keys [vars enabled]} (get matches id+attrs)]
(when
enabled
(binding
[*session*
session
*mutable-session*
(volatile! session)
*match*
vars]
(execute-fn (fn* [] (then-fn session vars)) node-id)
@*mutable-session*)))
session)))
session
then-queue)
session
(reduce
(fn
[session node-id]
(let
[{:keys [then-finally-fn]} (get beta-nodes node-id)]
(binding
[*session* session *mutable-session* (volatile! session)]
(execute-fn (fn* [] (then-finally-fn session)) node-id)
@*mutable-session*)))
session
then-finally-queue)]
(if-let
[limit (get opts :recursion-limit 16)]
(if
(= 0 *recur-countdown*)
(throw-recursion-limit session limit *executed-nodes*)
(binding
[*recur-countdown*
(if (nil? *recur-countdown*) limit (dec *recur-countdown*))
*executed-nodes*
(conj (or *executed-nodes* []) @*node-id->triggered-node-ids)]
(fire-rules session opts)))
(fire-rules session opts)))
session))))