Skip to content

Commit aa9fe4b

Browse files
rustagirmongoKart
andcommitted
DOCSP-44703: thread local variable getter/setter (#119)
* DOCSP-44703: thread local variable getter/setter * wording fix Co-authored-by: Mike Woofter <[email protected]> --------- Co-authored-by: Mike Woofter <[email protected]> (cherry picked from commit e3f6a21)
1 parent 6dba03b commit aa9fe4b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

snooty.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ toc_landing_pages = [
1313
"/quick-start-rails",
1414
"/quick-start-sinatra",
1515
"/interact-data/specify-query",
16-
"/issues-and-help"
16+
"/issues-and-help",
1717
]
1818

1919
[constants]
@@ -31,5 +31,6 @@ server-manual = "Server manual"
3131
api = "https://www.mongodb.com/docs/mongoid/current/api"
3232
ruby-api = "https://www.mongodb.com/docs/ruby-driver/current/api"
3333
active-record-docs = "https://guides.rubyonrails.org"
34+
ruby-lang-api = "https://docs.ruby-lang.org/en/3.4"
3435
shared-library = "Automatic Encryption Shared Library"
3536
mdb-server = "MongoDB Server"

source/data-modeling/callbacks.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ instance:
162162
:emphasize-lines: 6, 10-15
163163
:dedent:
164164

165+
.. _mongoid-callbacks-thread-local-vars:
166+
167+
Thread-Local Variables
168+
~~~~~~~~~~~~~~~~~~~~~~
169+
170+
If you have embedded child documents in an association that has
171+
``cascade_callbacks: true`` configured, then the embedded child
172+
callbacks are executed within a {+language+} `Fiber
173+
<{+ruby-lang-api+}/Fiber.html>`__. This means that if you are using the
174+
``Thread#[]`` and ``Thread#[]=`` methods to get and set fiber-local
175+
variables, those callbacks are not reading or setting the values you expect.
176+
177+
We recommend that you use the ``Thread#thread_variable_get`` and
178+
``Thread#thread_variable_set`` methods to get and set true
179+
thread-local variables. For convenience, {+odm+} v9.0.3 introduces
180+
the `Mongoid::Threaded.get <{+api+}/Mongoid/Threaded.html#get-instance_method>`__
181+
and `Mongoid::Threaded.set <{+api+}/Mongoid/Threaded.html#set-instance_method>`__
182+
methods to implement this functionality.
183+
165184
Additional Information
166185
----------------------
167186

source/whats-new.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ Removal of Deprecated Functionality
178178
- The deprecated class ``{+odm+}::Errors::InvalidStorageParent`` has
179179
been removed.
180180

181+
Get and Set Thread-Local Variables
182+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183+
184+
.. versionadded:: 9.0.3
185+
186+
You can use the `Mongoid::Threaded.get <{+api+}/Mongoid/Threaded.html#get-instance_method>`__
187+
and `Mongoid::Threaded.set <{+api+}/Mongoid/Threaded.html#set-instance_method>`__
188+
methods to query and modify thread-local variables. To learn when to use
189+
these methods, see the :ref:`mongoid-callbacks-thread-local-vars`
190+
section of the Callbacks guide.
191+
181192
Index Verification Configuration
182193
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183194

0 commit comments

Comments
 (0)