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

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

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from

Conversation

robhanlon22
Copy link
Contributor

Resolves #22.

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


(defn current-session
[]
(or (.get ^InheritableThreadLocal itl) *session*))
Copy link
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