aroemers / mount-lite

mount, but different and light
https://cljdoc.org/d/functionalbytes/mount-lite/
Eclipse Public License 1.0
102 stars 8 forks source link

Breaking change: don't spawn child thread in with-session #25

Closed robhanlon22 closed 1 year ago

robhanlon22 commented 3 years ago

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 the InheritableThreadLocal is trying to handle. However, the InheritableThreadLocal doesn't play nicely with futures and agents, which is what #24 remediates. Overall, I think that not spawning an asynchronous task in with-session would be more predictable, and pointing consumers at bound-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 of with-session, which consumers can opt to use instead, much like Clojure provides bound-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.

aroemers commented 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.