File tree Expand file tree Collapse file tree 1 file changed +33
-14
lines changed
Expand file tree Collapse file tree 1 file changed +33
-14
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,24 @@ def value=(value)
115115 value
116116 end
117117
118+ # Bind the given value to thread local storage during
119+ # execution of the given block.
120+ #
121+ # @param [Object] value the value to bind
122+ # @yield the operation to be performed with the bound variable
123+ # @return [Object] the value
124+ def bind ( value , &block )
125+ if block_given?
126+ old_value = self . value
127+ begin
128+ self . value = value
129+ yield
130+ ensure
131+ self . value = old_value
132+ end
133+ end
134+ end
135+
118136 protected
119137
120138 # @!visibility private
@@ -143,21 +161,22 @@ def self.thread_finalizer(array)
143161 end
144162 end
145163
146- # Bind the given value to thread local storage during
147- # execution of the given block.
148- #
149- # @param [Object] value the value to bind
150- # @yield the operation to be performed with the bound variable
151- # @return [Object] the value
152- def bind ( value , &block )
153- if block_given?
154- old_value = self . value
155- begin
156- self . value = value
157- yield
158- ensure
159- self . value = old_value
164+ private
165+
166+ # This exists only for use in testing
167+ # @!visibility private
168+ def value_for ( thread )
169+ if array = thread [ :__threadlocal_array__ ]
170+ value = array [ @index ]
171+ if value . nil?
172+ @default
173+ elsif value . equal? ( NIL_SENTINEL )
174+ nil
175+ else
176+ value
160177 end
178+ else
179+ @default
161180 end
162181 end
163182 end
You can’t perform that action at this time.
0 commit comments