Module: OpenHAB::Core::ThreadLocal
- Includes:
- Log
- Included in:
- DSL::Items::TimedCommand::GenericItem::TimedCommandCancelRule, DSL::Rules, DSL::Rules::AutomationRule, DSL::Timers::Timer
- Defined in:
- lib/openhab/core/thread_local.rb
Overview
Manages thread local varaibles for access inside of blocks
Instance Method Summary collapse
-
#thread_local(**values) ⇒ Object
Execute the supplied block with the supplied values set for the currently running thread The previous values for each key are restored after the block is executed.
Methods included from Log
Instance Method Details
#thread_local(**values) ⇒ Object
Execute the supplied block with the supplied values set for the currently running thread The previous values for each key are restored after the block is executed
20 21 22 23 24 25 26 27 |
# File 'lib/openhab/core/thread_local.rb', line 20 def thread_local(**values) old_values = values.map { |key, _value| [key, Thread.current[key]] }.to_h values.each { |key, value| Thread.current[key] = value } logger.trace "Executing block with thread local context: #{values} - old context: #{old_values}" yield ensure old_values.each { |key, value| Thread.current[key] = value } end |