Method: Concurrent::Future#wait_or_cancel

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

#wait_or_cancel(timeout) ⇒ Boolean

Wait the given number of seconds for the operation to complete. On timeout attempt to cancel the operation.

Parameters:

  • timeout (Numeric)

    the maximum time in seconds to wait.

Returns:

  • (Boolean)

    true if the operation completed before the timeout else false



121
122
123
124
125
126
127
128
129
# File 'lib/concurrent-ruby/concurrent/future.rb', line 121

def wait_or_cancel(timeout)
  wait(timeout)
  if complete?
    true
  else
    cancel
    false
  end
end