Skip to content

Create a binding context within a session so binding conveyance works#24

Closed
robhanlon22 wants to merge 6 commits intoaroemers:2.xfrom
robhanlon22:binding-for-session
Closed

Create a binding context within a session so binding conveyance works#24
robhanlon22 wants to merge 6 commits intoaroemers:2.xfrom
robhanlon22:binding-for-session

Conversation

@robhanlon22
Copy link
Copy Markdown
Contributor

Resolves #22.

Comment thread src/mount/lite.clj Outdated
Comment on lines +222 to +232
`(let [p# (promise)]
{:thread (doto (Thread. (fn []
(.set ^InheritableThreadLocal @#'itl (Thread/currentThread))
(try
(deliver p# (do ~@body))
(catch Throwable t#
(deliver p# t#)
(throw t#))
(finally
(stop)))))
(binding [*session* (new-session)]
(.set ^InheritableThreadLocal itl *session*)
(try
(deliver p# (do ~@body))
(catch Throwable t#
(deliver p# t#)
(throw t#))
(finally
(stop))))))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be converted to a future, which can be derefed directly and is run within a thread implicitly. However, I didn't want to make a potentially breaking change without checking with you first, @aroemers.

Comment thread src/mount/lite.clj

(defn current-session
[]
(or (.get ^InheritableThreadLocal itl) *session*))
Copy link
Copy Markdown
Contributor Author

@robhanlon22 robhanlon22 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combining the approaches of using the InheritableThreadLocal and a binding so we can fall back to the *session* if the InheritableThreadLocal's value is missing.

@robhanlon22 robhanlon22 changed the title Create a binding context within a session so binding conveyance works Make *itl* dynamic so binding conveyance works Sep 25, 2020
@robhanlon22 robhanlon22 changed the title Make *itl* dynamic so binding conveyance works Create a binding context within a session so binding conveyance works Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sessions don't play well with futures and agents

1 participant