Class: ThreadAttrAccessor::FiberStorage
- Inherits:
-
Object
- Object
- ThreadAttrAccessor::FiberStorage
- Defined in:
- lib/thread_attr_accessor.rb
Instance Attribute Summary collapse
-
#fiber ⇒ Object
readonly
Returns the value of attribute fiber.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(fiber = Fiber.current, thread = Thread.current) ⇒ FiberStorage
constructor
A new instance of FiberStorage.
Constructor Details
#initialize(fiber = Fiber.current, thread = Thread.current) ⇒ FiberStorage
Returns a new instance of FiberStorage.
33 34 35 36 |
# File 'lib/thread_attr_accessor.rb', line 33 def initialize(fiber = Fiber.current, thread = Thread.current) @fiber = fiber @thread = thread end |
Instance Attribute Details
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
32 33 34 |
# File 'lib/thread_attr_accessor.rb', line 32 def fiber @fiber end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
32 33 34 |
# File 'lib/thread_attr_accessor.rb', line 32 def thread @thread end |
Instance Method Details
#[](key) ⇒ Object
38 39 40 |
# File 'lib/thread_attr_accessor.rb', line 38 def [](key) fiber.fiber_variable_get(key) end |
#[]=(key, value) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/thread_attr_accessor.rb', line 42 def []=(key, value) fiber.fiber_variable_set(key, value) if fiber.parent_fiber.nil? thread.thread_variable_set(key, value) end value end |
#has_key?(key) ⇒ Boolean
51 52 53 |
# File 'lib/thread_attr_accessor.rb', line 51 def has_key?(key) fiber.fiber_variable?(key) end |