Preserve thread bindings when running fetchers#21
Preserve thread bindings when running fetchers#21nicoberger-a wants to merge 1 commit intofuncool:masterfrom
Conversation
|
Hi, Thanks for the contribution. I have had similar issues with logging contexts too. You mention a db connection - for this you should be using the What are your thoughts? |
|
Hi @oliyh, thanks for looking into my proposed changes, and thanks for the mention of I'm not totally sure what would be the implications of using |
|
You can achieve what you need using How does that seem to you? Cheers |
|
Hi @oliyh, Thanks for the example. It helped me understand That would work, in the sense that any potential bindings could be passed in that way, and the function could do anything with those values. However, would adding For reference from other projects, lacinia uses To explain more about my use case, I'm using lacinia with superlifter (thanks by the way, it's amazing!), and I use timbre for logging. Timbre is configured via a To summarize, I understand that more complex scenarios could need something different than Thanks again, and I look forward to your thoughts. |
When urania runs a fetcher, either from run-fetch or run-fetch-multi, it submits a function to an executor so it runs on a different thread.
However, it should wrap the function with bound-fn to preserve any bindings that might exist on the current thread. Not doing so could result in unexpected results if the function relies on dynamic values shared via thread bindings, like a DB connection or logging configuration.
Relevant code:
urania/src/urania/core.cljc
Lines 197 to 206 in 4043efe