Class: Farce::Concurrent::ThreadLocalVar
- Inherits:
-
LocalVar
- Object
- LocalVar
- Farce::Concurrent::ThreadLocalVar
- Defined in:
- lib/farce/concurrent/thread_local_var.rb
Overview
A replacement for concurrent-ruby's Concurrent::ThreadLocalVar
May or may not be Ractor-shareable depending on provided default values.
Instance Attribute Summary collapse
-
#value ⇒ Object
The current value of the thread-local variable.
Instance Method Summary collapse
-
#bind(value) { ... } ⇒ BasicObject
The result of the block.
-
#initialize ⇒ ThreadLocalVar
constructor
A new instance of ThreadLocalVar.
Methods included from Abstract::Value
Constructor Details
#initialize(default = nil) ⇒ ThreadLocalVar #initialize { ... } ⇒ ThreadLocalVar
Returns a new instance of ThreadLocalVar.
25 |
# File 'lib/farce/concurrent/thread_local_var.rb', line 25 def initialize(...) = super(:thread, ...) |
Instance Attribute Details
#value ⇒ Object
Returns the current value of the thread-local variable.
19 20 21 22 23 24 25 26 |
# File 'lib/farce/concurrent/thread_local_var.rb', line 19 class ThreadLocalVar < LocalVar # @overload initialize(default = nil) # @param default [Object] the default value for the thread-local variable # # @overload initialize # @yield the block to compute the default value for the thread-local variable def initialize(...) = super(:thread, ...) end |
Instance Method Details
#bind(value) { ... } ⇒ BasicObject
Returns the result of the block.
19 20 21 22 23 24 25 26 |
# File 'lib/farce/concurrent/thread_local_var.rb', line 19 class ThreadLocalVar < LocalVar # @overload initialize(default = nil) # @param default [Object] the default value for the thread-local variable # # @overload initialize # @yield the block to compute the default value for the thread-local variable def initialize(...) = super(:thread, ...) end |