Skip to content

Commit

Permalink
[mod] [Signal API] callsite -> callsite-id
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Dec 7, 2023
1 parent 6c05faf commit bb63fc6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/taoensso/encore/signals.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
#?(:clj
(defn filterable-expansion
"Low-level util for writing macros with compile-time and runtime filtering.
Returns {:keys [callsite elide? allow?]}.
Returns {:keys [callsite-id elide? allow?]}.
`macro-opts`, `opts-arg` are both of form:
{:keys [kind id level sample rate-limit when]}.
Expand All @@ -342,15 +342,15 @@
forms in `opts-arg`."

[{:as macro-opts
:keys [loc opts-arg sf-arity ct-sig-filter rt-sig-filter]}]
:keys [location opts-arg sf-arity ct-sig-filter rt-sig-filter]}]

(when-not (or (nil? opts-arg) (map? opts-arg))
(throw
(ex-info "[encore/signals] `filterable-expansion` `opts-arg` must be a compile-time map"
{:loc loc, :opts-arg opts-arg})))
{:location location, :opts-arg opts-arg})))

(let [callsite (callsite-counter) ; Unique expansion id
{:keys [ns line column file]} loc
(let [callsite-id (callsite-counter) ; Unique expansion id
{:keys [ns line column file]} location

;; Note that while `opts-arg` must be a const (compile-time) map,
;; its vals are arb forms that may need eval.
Expand All @@ -371,7 +371,7 @@
:id (enc/const-form id-form)
:level (enc/const-form level-form)})))

base-rv {:callsite callsite}]
base-rv {:callsite-id callsite-id}]

(if elide?
(assoc base-rv :allow? false, :elide? true)
Expand All @@ -391,19 +391,19 @@

filter-form
(when-let [filter-form-entry (or (find-opt-form :filter) (find-opt-form :when))]
`(let [~'this-callsite ~callsite] ~(val filter-form-entry)))
`(let [~'this-callsite-id ~callsite-id] ~(val filter-form-entry)))

rl-form ; Nb last (increments count)
(when-let [spec-form (get-opt-form :rate-limit)]
`(if (callsite-limit!? ~callsite ~spec-form nil) false true))]
`(if (callsite-limit!? ~callsite-id ~spec-form nil) false true))]

`(and ~@(filter some? [sample-form sf-form filter-form rl-form])))]

(assoc base-rv :allow? allow?-form))))))

(comment
(filterable-expansion
{:sf-arity 2, :rt-sig-filter `*foo*, :loc {:ns (str *ns*)}
{:sf-arity 2, :rt-sig-filter `*foo*, :location {:ns (str *ns*)}
:opts-arg
{:filter 'false
:level (do :info)
Expand Down

0 comments on commit bb63fc6

Please sign in to comment.