Class: ThreadAttrAccessor::FiberStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/thread_attr_accessor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fiberObject (readonly)

Returns the value of attribute fiber.



32
33
34
# File 'lib/thread_attr_accessor.rb', line 32

def fiber
  @fiber
end

#threadObject (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/thread_attr_accessor.rb', line 51

def has_key?(key)
  fiber.fiber_variable?(key)
end