Method: Concurrent::Actor.spawn

Defined in:
lib/concurrent/actor.rb

.spawn(*args, &block) ⇒ Reference

Spawns a new actor. Concurrent::Actor::AbstractContext.spawn allows to omit class parameter. To see the list of avaliable options see Concurrent::Actor::Core#initialize

Examples:

by class and name

Actor.spawn(AdHoc, :ping1) { -> message { message } }

by option hash

inc2 = Actor.spawn(class:    AdHoc,
                   name:     'increment by 2',
                   args:     [2],
                   executor: Concurrent.global_io_executor) do |increment_by|
  lambda { |number| number + increment_by }
end
inc2.ask!(2) # => 4

Parameters:

Returns:

See Also:



67
68
69
70
71
72
73
# File 'lib/concurrent/actor.rb', line 67

def self.spawn(*args, &block)
  if Actor.current
    Core.new(to_spawn_options(*args).merge(parent: Actor.current), &block).reference
  else
    root.ask([:spawn, to_spawn_options(*args), block]).value!
  end
end