Method: Concurrent::FiberLocalVar#bind

Defined in:
lib/concurrent-ruby/concurrent/atomic/fiber_local_var.rb

#bind(value) { ... } ⇒ Object

Bind the given value to fiber local storage during execution of the given block.

Parameters:

  • value (Object)

    the value to bind

Yields:

  • the operation to be performed with the bound variable

Returns:

  • (Object)

    the value



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/concurrent-ruby/concurrent/atomic/fiber_local_var.rb', line 86

def bind(value)
  if block_given?
    old_value = self.value
    self.value = value
    begin
      yield
    ensure
      self.value = old_value
    end
  end
end