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)
115
115
value
116
116
end
117
117
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
+
118
136
protected
119
137
120
138
# @!visibility private
@@ -143,21 +161,22 @@ def self.thread_finalizer(array)
143
161
end
144
162
end
145
163
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
160
177
end
178
+ else
179
+ @default
161
180
end
162
181
end
163
182
end
You can’t perform that action at this time.
0 commit comments