Method: Concurrent::Semaphore#try_acquire

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

#try_acquire(permits = 1, timeout = nil) ⇒ true, ...

Acquires the given number of permits from this semaphore,

only if all are available at the time of invocation or within
`timeout` interval. If a block is given, yields to it if the permits
were successfully acquired, and releases them afterward, returning the
block's return value.

Parameters:

  • permits (Fixnum) (defaults to: 1)

    the number of permits to acquire

  • timeout (Fixnum) (defaults to: nil)

    the number of seconds to wait for the counter or ‘nil` to return immediately

Returns:

  • (true, false, nil, BasicObject)

    ‘false` if no permits are available, `true` when acquired a permit. If a block is given, the block’s return value is returned if the permits were acquired; if not, ‘nil` is returned.

Raises:

  • (ArgumentError)

    if ‘permits` is not an integer or is less than zero



161
162
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161

class Semaphore < SemaphoreImplementation
end