Method: Concurrent::Agent#send

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

#send(*args, &action) {|agent, value, *args| ... } ⇒ Boolean

Dispatches an action to the Agent and returns immediately. Subsequently, in a thread from a thread pool, the #value will be set to the return value of the action. Action dispatches are only allowed when the Agent is not #failed?.

The action must be a block/proc/lambda which takes 1 or more arguments. The first argument is the current #value of the Agent. Any arguments passed to the send method via the args parameter will be passed to the action as the remaining arguments. The action must return the new value of the Agent.

Parameters:

  • args (Array<Object>)

    zero or more arguments to be passed to the action

  • action (Proc)

    the action dispatch to be enqueued

Yields:

  • (agent, value, *args)

    process the old value and return the new

Yield Parameters:

  • value (Object)

    the current #value of the Agent

  • args (Array<Object>)

    zero or more arguments to pass to the action

Yield Returns:

  • (Object)

    the new value of the Agent

Returns:

  • (Boolean)

    true if the action is successfully enqueued, false if the Agent is #failed?



277
278
279
# File 'lib/concurrent-ruby/concurrent/agent.rb', line 277

def send(*args, &action)
  enqueue_action_job(action, args, Concurrent.global_fast_executor)
end