Method: Concurrent::Agent#wait

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

#wait(timeout = nil) ⇒ Boolean

Blocks the current thread until all actions dispatched thus far, from this thread or nested by the Agent, have occurred, or the timeout (in seconds) has elapsed. Will block indefinitely when timeout is nil or not given.

Provided mainly for consistency with other classes in this library. Prefer the various ‘await` methods instead.

NOTE Never, *under any circumstances*, call any of the “await” methods (#await, #await_for, #await_for!, and #wait) from within an action block/proc/lambda. The call will block the Agent and will always fail. Calling either #await or #wait (with a timeout of ‘nil`) will hopelessly deadlock the Agent with no possibility of recovery.

Parameters:

  • timeout (Float) (defaults to: nil)

    the maximum number of seconds to wait

Returns:

  • (Boolean)

    true if all actions complete before timeout else false



393
394
395
396
397
# File 'lib/concurrent-ruby/concurrent/agent.rb', line 393

def wait(timeout = nil)
  latch = Concurrent::CountDownLatch.new(1)
  enqueue_await_job(latch)
  latch.wait(timeout)
end