Method: Concurrent::Agent#restart

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

#restart(new_value, opts = {}) ⇒ Boolean

When an Agent is #failed?, changes the Agent #value to ‘new_value` then un-fails the Agent so that action dispatches are allowed again. If the `:clear_actions` option is give and true, any actions queued on the Agent that were being held while it was failed will be discarded, otherwise those held actions will proceed. The `new_value` must pass the validator if any, or `restart` will raise an exception and the Agent will remain failed with its old #value and #error. Observers, if any, will not be notified of the new state.

Parameters:

  • new_value (Object)

    the new value for the Agent once restarted

  • opts (Hash) (defaults to: {})

    the configuration options

Options Hash (opts):

  • :clear_actions (Symbol)

    true if all enqueued but unprocessed actions should be discarded on restart, else false (default: false)

Returns:

  • (Boolean)

    true

Raises:

  • (Concurrent:AgentError)

    when not failed



424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/concurrent-ruby/concurrent/agent.rb', line 424

def restart(new_value, opts = {})
  clear_actions = opts.fetch(:clear_actions, false)
  synchronize do
    raise Error.new('agent is not failed') unless failed?
    raise ValidationError unless ns_validate(new_value)
    @current.value = new_value
    @error.value   = nil
    @queue.clear if clear_actions
    ns_post_next_job unless @queue.empty?
  end
  true
end