Class: Concurrent::Actor::Reference
- Inherits:
-
Object
- Object
- Concurrent::Actor::Reference
- Includes:
- PublicDelegations, TypeCheck
- Defined in:
- lib/concurrent/actor/reference.rb
Overview
Reference is public interface of Actor instances. It is used for sending messages and can be freely passed around the program. It also provides some basic information about the actor, see PublicDelegations.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#ask(message, ivar = IVar.new) ⇒ IVar
testing and when it returns very shortly.
-
#ask!(message, ivar = IVar.new) ⇒ Object
testing and when it returns very shortly.
- #dead_letter_routing ⇒ Object
- #message(message, ivar = nil) ⇒ Object
-
#tell(message) ⇒ Reference
(also: #<<)
tells message to the actor, returns immediately.
- #to_s ⇒ Object (also: #inspect)
Methods included from PublicDelegations
#context_class, #executor, #name, #parent, #path, #reference
Methods included from TypeCheck
#Child!, #Child?, #Match!, #Match?, #Type!, #Type?
Instance Method Details
#==(other) ⇒ Object
72 73 74 |
# File 'lib/concurrent/actor/reference.rb', line 72 def ==(other) Type? other, self.class and other.send(:core) == core end |
#ask(message, ivar = IVar.new) ⇒ IVar
it’s a good practice to use tell whenever possible. Ask should be used only for
testing and when it returns very shortly. It can lead to deadlock if all threads in global_task_pool will block on while asking. It’s fine to use it form outside of actors and global_task_pool.
sends message to the actor and asks for the result of its processing, returns immediately
37 38 39 |
# File 'lib/concurrent/actor/reference.rb', line 37 def ask(, ivar = IVar.new) , ivar end |
#ask!(message, ivar = IVar.new) ⇒ Object
it’s a good practice to use tell whenever possible. Ask should be used only for
testing and when it returns very shortly. It can lead to deadlock if all threads in global_task_pool will block on while asking. It’s fine to use it form outside of actors and global_task_pool.
sends message to the actor and asks for the result of its processing, blocks
51 52 53 |
# File 'lib/concurrent/actor/reference.rb', line 51 def ask!(, ivar = IVar.new) ask(, ivar).value! end |
#dead_letter_routing ⇒ Object
62 63 64 |
# File 'lib/concurrent/actor/reference.rb', line 62 def dead_letter_routing core.dead_letter_routing end |
#message(message, ivar = nil) ⇒ Object
56 57 58 59 |
# File 'lib/concurrent/actor/reference.rb', line 56 def (, ivar = nil) core.on_envelope Envelope.new(, ivar, Actor.current || Thread.current, self) return ivar || self end |
#tell(message) ⇒ Reference Also known as: <<
tells message to the actor, returns immediately
22 23 24 |
# File 'lib/concurrent/actor/reference.rb', line 22 def tell() , nil end |
#to_s ⇒ Object Also known as: inspect
66 67 68 |
# File 'lib/concurrent/actor/reference.rb', line 66 def to_s "#<#{self.class} #{path} (#{actor_class})>" end |