Skip to content

Commit

Permalink
[new] Simplify signal expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Aug 26, 2024
1 parent bbfe611 commit 3068ccf
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/taoensso/telemere/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,12 @@
:sf-arity 4
:ct-sig-filter ct-sig-filter
:*rt-sig-filter* `*rt-sig-filter*}
opts)]

(assoc opts :bound-forms
{:kind '__kind
:ns '__ns
:id '__id
:level '__level}))]

(if elide?
run-form
Expand Down Expand Up @@ -716,33 +721,35 @@
;; (run-fn-form)
;; (let [...]))))

`(enc/if-not ~allow? ; Allow to throw at call
~run-form
(let [;;; Allow to throw at call
~'__inst ~inst-form
~'__level ~level-form
~'__kind ~kind-form
~'__id ~id-form
~'__ns ~ns-form
~'__thread ~thread-form
~'__root0 ~root-form0 ; ?{:keys [id uid]}

~@into-let-form ; Inject conditional bindings
signal# ~signal-delay-form]

(dispatch-signal!
;; Unconditionally send same wrapped signal to all handlers.
;; Each handler will use wrapper for handler filtering,
;; unwrapping (realizing) only allowed signals.
(WrappedSignal. ~'__ns ~'__kind ~'__id ~'__level signal#))

(if ~'__run-result
( ~'__run-result signal#)
true))))))))
;; Unless otherwise specified, allow errors to throw on call
`(let [~'__kind ~kind-form
~'__ns ~ns-form
~'__id ~id-form
~'__level ~level-form]

(enc/if-not ~allow?
~run-form
(let [~'__inst ~inst-form
~'__thread ~thread-form
~'__root0 ~root-form0 ; ?{:keys [id uid]}

~@into-let-form ; Inject conditional bindings
signal# ~signal-delay-form]

(dispatch-signal!
;; Unconditionally send same wrapped signal to all handlers.
;; Each handler will use wrapper for handler filtering,
;; unwrapping (realizing) only allowed signals.
(WrappedSignal. ~'__ns ~'__kind ~'__id ~'__level signal#))

(if ~'__run-result
( ~'__run-result signal#)
true)))))))))

(comment
(with-signal (signal! {:level :warn :let [x :x] :msg ["Test" "message" x] :data {:a :A :x x} :run (+ 1 2)}))
(macroexpand '(signal! {:level :warn :let [x :x] :msg ["Test" "message" x] :data {:a :A :x x} :run (+ 1 2)}))
(macroexpand '(signal! {:level :info}))

(do
(println "---")
Expand Down

0 comments on commit 3068ccf

Please sign in to comment.