Class: Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/thread/inheritable_attributes.rb,
lib/thread/inheritable_attributes/version.rb

Defined Under Namespace

Modules: InheritableAttributes

Constant Summary collapse

INHERITABLE_ATTRIBUTES_MUTEX =
Mutex.new

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Thread

Returns a new instance of Thread.



7
8
9
10
11
12
13
# File 'lib/thread/inheritable_attributes.rb', line 7

def initialize(*args, &block)
  inheritable_attributes = Thread.current.inheritable_attributes
  _initialize(*args) do |*block_args|
    Thread.current[:inheritable_attributes] = inheritable_attributes
    block.call(block_args)
  end
end

Instance Method Details

#_initializeObject



5
# File 'lib/thread/inheritable_attributes.rb', line 5

alias_method :_initialize, :initialize

#get_inheritable_attribute(key) ⇒ Object



15
16
17
18
19
# File 'lib/thread/inheritable_attributes.rb', line 15

def get_inheritable_attribute(key)
  INHERITABLE_ATTRIBUTES_MUTEX.synchronize do
    inheritable_attributes[key]
  end
end

#set_inheritable_attribute(key, value) ⇒ Object



21
22
23
24
25
# File 'lib/thread/inheritable_attributes.rb', line 21

def set_inheritable_attribute(key, value)
  INHERITABLE_ATTRIBUTES_MUTEX.synchronize do
    inheritable_attributes[key] = value
  end
end