Class: Concurrent::Actor::Reference
- Inherits:
-
Object
- Object
- Concurrent::Actor::Reference
- Includes:
- PublicDelegations, TypeCheck
- Defined in:
- lib/concurrent-ruby-edge/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 application. It also provides some basic information about the actor, see PublicDelegations.
AdHoc.spawn('printer') { -> { puts } }
# => #<Concurrent::Actor::Reference:0x7fd0d2883218 /printer (Concurrent::Actor::Utils::AdHoc)>
# ^object_id ^path ^context class
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#ask(message, future = Concurrent::Promises.resolvable_future) ⇒ Promises::Future
(also: #ask_op)
Supplied future.
-
#ask!(message, future = Concurrent::Promises.resolvable_future) ⇒ Object
Sends the message synchronously and blocks until the message is processed.
- #dead_letter_routing ⇒ Object
- #map(messages) ⇒ Object
- #message(message, future = nil) ⇒ Object
-
#tell(message) ⇒ Reference
(also: #<<)
Sends the message asynchronously to the actor and immediately returns ‘self` (the reference) allowing to chain message telling.
- #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
98 99 100 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 98 def ==(other) Type? other, self.class and other.send(:core) == core end |
#ask(message, future = Concurrent::Promises.resolvable_future) ⇒ Promises::Future Also known as: ask_op
it’s a good practice to use #tell whenever possible. Results can be sent back with other messages. Ask should be used only for testing and when it returns very shortly. It can lead to deadlock if all threads in global_io_executor will block on while asking. It’s fine to use it form outside of actors and global_io_executor.
Returns supplied future.
52 53 54 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 52 def ask(, future = Concurrent::Promises.resolvable_future) , future end |
#ask!(message, future = Concurrent::Promises.resolvable_future) ⇒ Object
it’s a good practice to use #tell whenever possible. Results can be sent back with other messages. Ask should be used only for testing and when it returns very shortly. It can lead to deadlock if all threads in global_io_executor will block on while asking. It’s fine to use it form outside of actors and global_io_executor.
Sends the message synchronously and blocks until the message is processed. Raises on error.
73 74 75 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 73 def ask!(, future = Concurrent::Promises.resolvable_future) ask(, future).value! end |
#dead_letter_routing ⇒ Object
88 89 90 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 88 def dead_letter_routing core.dead_letter_routing end |
#map(messages) ⇒ Object
77 78 79 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 77 def map() .map { |m| self.ask(m) } end |
#message(message, future = nil) ⇒ Object
82 83 84 85 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 82 def (, future = nil) core.on_envelope Envelope.new(, future, Actor.current || Thread.current, self) return future ? future.with_hidden_resolvable : self end |
#tell(message) ⇒ Reference Also known as: <<
Sends the message asynchronously to the actor and immediately returns ‘self` (the reference) allowing to chain message telling.
35 36 37 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 35 def tell() , nil end |
#to_s ⇒ Object Also known as: inspect
92 93 94 |
# File 'lib/concurrent-ruby-edge/concurrent/actor/reference.rb', line 92 def to_s format '%s %s (%s)>', super[0..-2], path, actor_class end |