Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for runtime opts? #35

Closed
ptaoussanis opened this issue Nov 27, 2024 · 1 comment
Closed

Improve support for runtime opts? #35

ptaoussanis opened this issue Nov 27, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request 👍's welcome Looking for upvotes to gauge interest level
Milestone

Comments

@ptaoussanis
Copy link
Member

The below currently throws an "Invalid level" exception:

(defn my-opts [msg data] {:msg msg :data data})
(t/event! ::my-id (my-opts "hello" {:foo :bar}))

Limitation

This is because Telemere currently expects provided opts to be a compile-time map. The map vals don't necessarily need to be compile-time consts, but the opts map itself does need to be.

This limitation could probably be relaxed or removed, and might be useful to do. At the very least the limitation should be clearly documented in the meantime, and it'd be nice if a clearer error message were thrown. Will take a look at this when I'm next on batched Telemere work.

Workarounds

In the meantime, folks wanting to do something like the above have a few options:

(1) Use a macro wrapper instead, e.g.:

(defmacro my-event! [msg data]
  (taoensso.encore/keep-callsite
    `(tel/event! ::my-id {:msg ~msg, :data ~data})))

Note that signal! is often easier to use when writing such wrappers.

(2) Use a wrapper fn instead, e.g.:

(defn my-event! [msg data]
  (tel/event! ::my-id {:msg msg, :data data}))

Though note that (2) will mean losing callsite information.

(3) Instead move the extra functionality you want to middleware, etc.

cc @Knotschi

@ptaoussanis ptaoussanis added enhancement New feature or request 👍's welcome Looking for upvotes to gauge interest level labels Nov 27, 2024
@ptaoussanis ptaoussanis added this to the v1 final milestone Nov 27, 2024
@ptaoussanis ptaoussanis self-assigned this Nov 27, 2024
@ptaoussanis
Copy link
Member Author

Update: after further thoughts and experimenting on this, I think it's actually probably best -not- to relax the restrictions on this since that can lead to unexpected results.

Instead, the next release will include:

  1. Additional mentions in the docs about this restriction.
  2. Support for single-arg (opts map) signal creators, which can help make custom wrappers easier.

I'll also see about improving error messages where possible 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 👍's welcome Looking for upvotes to gauge interest level
Projects
None yet
Development

No branches or pull requests

1 participant