Method: Concurrent::MVar#borrow

Defined in:
lib/concurrent-ruby/concurrent/mvar.rb

#borrow(timeout = nil) ⇒ Object

acquires lock on the from an MVAR, yields the value to provided block, and release lock. A timeout can be set to limit the time spent blocked, in which case it returns TIMEOUT if the time is exceeded.

Returns:

  • (Object)

    the value returned by the block, or TIMEOUT



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

def borrow(timeout = nil)
  @mutex.synchronize do
    wait_for_full(timeout)

    # If we timed out we'll still be empty
    if unlocked_full?
      yield @value
    else
      TIMEOUT
    end
  end
end