Closed robhanlon22 closed 1 year ago
Thank you for the suggestion. As mentioned in #22, it is indeed a known issue. A dynamic binding is not going to remedy this completely either; thread pools that have been created outside the session and not using Clojure's future
or bound-fn
still have this problem.
I do not intend to have a breaking change for mount-lite 2. Version 3.x (unreleased) fixes this issue, by having full control over sessions.
This change simplifies with-session to just create a new binding context with a new session. This is a breaking change, and would require a major version update, which could understandably not be desirable. However, I found that the behavior exhibited by the current behavior to be surprising and at times unpredictable.
Clojure provides
bound-fn
for precisely the use case that theInheritableThreadLocal
is trying to handle. However, theInheritableThreadLocal
doesn't play nicely with futures and agents, which is what #24 remediates. Overall, I think that not spawning an asynchronous task inwith-session
would be more predictable, and pointing consumers atbound-fn
for use with threads would be more in line with Clojure's binding design.This change also introduces
with-session*
, which is a function version ofwith-session
, which consumers can opt to use instead, much like Clojure providesbound-fn*
.This is mostly here as an idea, since it is quite a major API change. It also removes the auto-stopping functionality, as inner states may have been started with one of the extensions, and a consumer may want more control over how the inner session is stopped.