Method: Concurrent::Future#cancel

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

#cancelBoolean

Attempt to cancel the operation if it has not already processed. The operation can only be cancelled while still pending. It cannot be cancelled once it has begun processing or has completed.

Returns:

  • (Boolean)

    was the operation successfully cancelled.



99
100
101
102
103
104
105
106
# File 'lib/concurrent-ruby/concurrent/future.rb', line 99

def cancel
  if compare_and_set_state(:cancelled, :pending)
    complete(false, nil, CancelledOperationError.new)
    true
  else
    false
  end
end