Module: Concurrent::Actor
- Defined in:
- lib/concurrent/actor.rb,
lib/concurrent/actor/core.rb,
lib/concurrent/actor/root.rb,
lib/concurrent/actor/utils.rb,
lib/concurrent/actor/errors.rb,
lib/concurrent/actor/context.rb,
lib/concurrent/actor/envelope.rb,
lib/concurrent/actor/behaviour.rb,
lib/concurrent/actor/reference.rb,
lib/concurrent/actor/type_check.rb,
lib/concurrent/actor/utils/pool.rb,
lib/concurrent/actor/utils/ad_hoc.rb,
lib/concurrent/actor/utils/balancer.rb,
lib/concurrent/actor/utils/broadcast.rb,
lib/concurrent/actor/behaviour/awaits.rb,
lib/concurrent/actor/behaviour/buffer.rb,
lib/concurrent/actor/behaviour/linking.rb,
lib/concurrent/actor/behaviour/pausing.rb,
lib/concurrent/actor/behaviour/abstract.rb,
lib/concurrent/actor/public_delegations.rb,
lib/concurrent/actor/internal_delegations.rb,
lib/concurrent/actor/behaviour/supervising.rb,
lib/concurrent/actor/behaviour/termination.rb,
lib/concurrent/actor/behaviour/sets_results.rb,
lib/concurrent/actor/behaviour/removes_child.rb,
lib/concurrent/actor/behaviour/executes_context.rb,
lib/concurrent/actor/default_dead_letter_handler.rb,
lib/concurrent/actor/behaviour/errors_on_unknown_message.rb
Overview
Defined Under Namespace
Modules: Behaviour, InternalDelegations, PublicDelegations, TypeCheck, Utils Classes: AbstractContext, ActorTerminated, Context, Core, DefaultDeadLetterHandler, Envelope, Reference, RestartingContext, Root, UnknownMessage
Constant Summary collapse
- Error =
Class.new(StandardError)
Class Method Summary collapse
-
.current ⇒ Reference?
Current executing actor if any.
-
.root ⇒ Object
A root actor, a default parent of all actors spawned outside an actor.
-
.spawn(*args, &block) ⇒ Reference
Spawns a new actor.
-
.spawn!(*args, &block) ⇒ Object
as Actor.spawn but it’ll block until actor is initialized or it’ll raise exception on error.
- .to_spawn_options(*args) ⇒ Object
Class Method Details
.current ⇒ Reference?
Returns current executing actor if any.
33 34 35 |
# File 'lib/concurrent/actor.rb', line 33 def self.current Thread.current[:__current_actor__] end |
.root ⇒ Object
A root actor, a default parent of all actors spawned outside an actor
44 45 46 |
# File 'lib/concurrent/actor.rb', line 44 def self.root @root.value! end |
.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
67 68 69 70 71 72 73 |
# File 'lib/concurrent/actor.rb', line 67 def self.spawn(*args, &block) if Actor.current Core.new((*args).merge(parent: Actor.current), &block).reference else root.ask([:spawn, (*args), block]).value! end end |
.spawn!(*args, &block) ⇒ Object
as spawn but it’ll block until actor is initialized or it’ll raise exception on error
76 77 78 |
# File 'lib/concurrent/actor.rb', line 76 def self.spawn!(*args, &block) spawn((*args).merge(initialized: future = Concurrent.future), &block).tap { future.wait! } end |
.to_spawn_options(context_class, name, *args) ⇒ Object .to_spawn_options(opts) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/concurrent/actor.rb', line 87 def self.(*args) if args.size == 1 && args.first.is_a?(::Hash) args.first else { class: args[0], name: args[1], args: args[2..-1] } end end |