Module: Concurrent::Actor
- Defined in:
- lib/concurrent-ruby-edge/concurrent/actor.rb,
lib/concurrent-ruby-edge/concurrent/actor/core.rb,
lib/concurrent-ruby-edge/concurrent/actor/root.rb,
lib/concurrent-ruby-edge/concurrent/actor/utils.rb,
lib/concurrent-ruby-edge/concurrent/actor/errors.rb,
lib/concurrent-ruby-edge/concurrent/actor/context.rb,
lib/concurrent-ruby-edge/concurrent/actor/envelope.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour.rb,
lib/concurrent-ruby-edge/concurrent/actor/reference.rb,
lib/concurrent-ruby-edge/concurrent/actor/type_check.rb,
lib/concurrent-ruby-edge/concurrent/actor/utils/pool.rb,
lib/concurrent-ruby-edge/concurrent/actor/utils/ad_hoc.rb,
lib/concurrent-ruby-edge/concurrent/actor/utils/balancer.rb,
lib/concurrent-ruby-edge/concurrent/actor/utils/broadcast.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/awaits.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/buffer.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/linking.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/abstract.rb,
lib/concurrent-ruby-edge/concurrent/actor/public_delegations.rb,
lib/concurrent-ruby-edge/concurrent/actor/internal_delegations.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/supervising.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/sets_results.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/removes_child.rb,
lib/concurrent-ruby-edge/concurrent/actor/behaviour/executes_context.rb,
lib/concurrent-ruby-edge/concurrent/actor/default_dead_letter_handler.rb,
lib/concurrent-ruby-edge/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.
34 35 36 |
# File 'lib/concurrent-ruby-edge/concurrent/actor.rb', line 34 def self.current Thread.current[:__current_actor__] end |
.root ⇒ Object
A root actor, a default parent of all actors spawned outside an actor
49 50 51 |
# File 'lib/concurrent-ruby-edge/concurrent/actor.rb', line 49 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 available options see Concurrent::Actor::Core#initialize
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/concurrent-ruby-edge/concurrent/actor.rb', line 72 def self.spawn(*args, &block) = (*args) if [:executor] && [:executor].is_a?(ImmediateExecutor) raise ArgumentError, 'ImmediateExecutor is not supported' end if Actor.current Core.new(.merge(parent: Actor.current), &block).reference else root.ask([:spawn, , 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
85 86 87 |
# File 'lib/concurrent-ruby-edge/concurrent/actor.rb', line 85 def self.spawn!(*args, &block) spawn((*args).merge(initialized: future = Concurrent::Promises.resolvable_future), &block).tap { future.wait! } end |
.to_spawn_options(context_class, name, *args) ⇒ Object .to_spawn_options(opts) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/concurrent-ruby-edge/concurrent/actor.rb', line 96 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 |