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 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)
- - (undocumented) ==(other)
-
- (Promises::Future) ask(message, future = Concurrent::Promises.resolvable_future)
testing and when it returns very shortly.
-
- (Object) ask!(message, future = Concurrent::Promises.resolvable_future)
Sends the message synchronously and blocks until the message is processed.
- - (undocumented) Child!(value, *types) included from TypeCheck
- - (Boolean) Child?(value, *types) included from TypeCheck
- - (undocumented) context_class (also: #actor_class) included from PublicDelegations
- - (undocumented) dead_letter_routing
- - (undocumented) executor included from PublicDelegations
- - (undocumented) map(messages)
- - (undocumented) Match!(value, *types) included from TypeCheck
- - (Boolean) Match?(value, *types) included from TypeCheck
- - (undocumented) message(message, future = nil)
- - (undocumented) name included from PublicDelegations
- - (undocumented) parent included from PublicDelegations
- - (undocumented) path included from PublicDelegations
- - (undocumented) reference (also: #ref) included from PublicDelegations
-
- (Reference) tell(message)
(also: #<<)
Sends the message asynchronously to the actor and immediately returns
self
(the reference) allowing to chain message telling. - - (undocumented) to_s (also: #inspect)
- - (undocumented) Type!(value, *types) included from TypeCheck
- - (Boolean) Type?(value, *types) included from TypeCheck
Instance Method Details
- (undocumented) ==(other)
97 98 99 |
# File 'lib/concurrent/actor/reference.rb', line 97 def ==(other) Type? other, self.class and other.send(:core) == core end |
- (Promises::Future) ask(message, future = Concurrent::Promises.resolvable_future)
it's a good practice to use tell whenever possible. Ask should be used only for
it's a good practice to use #tell whenever possible. Results can be send 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.
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.
54 55 56 |
# File 'lib/concurrent/actor/reference.rb', line 54 def ask(, future = Concurrent::Promises.resolvable_future) , future end |
- (Object) ask!(message, future = Concurrent::Promises.resolvable_future)
it's a good practice to use #tell whenever possible. Results can be send 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.
72 73 74 |
# File 'lib/concurrent/actor/reference.rb', line 72 def ask!(, future = Concurrent::Promises.resolvable_future) ask(, future).value! end |
- (undocumented) Child!(value, *types) Originally defined in module TypeCheck
- (Boolean) Child?(value, *types) Originally defined in module TypeCheck
- (undocumented) context_class Also known as: actor_class Originally defined in module PublicDelegations
- (undocumented) dead_letter_routing
87 88 89 |
# File 'lib/concurrent/actor/reference.rb', line 87 def dead_letter_routing core.dead_letter_routing end |
- (undocumented) executor Originally defined in module PublicDelegations
- (undocumented) map(messages)
76 77 78 |
# File 'lib/concurrent/actor/reference.rb', line 76 def map() .map { |m| self.ask(m) } end |
- (undocumented) Match!(value, *types) Originally defined in module TypeCheck
- (Boolean) Match?(value, *types) Originally defined in module TypeCheck
- (undocumented) message(message, future = nil)
81 82 83 84 |
# File 'lib/concurrent/actor/reference.rb', line 81 def (, future = nil) core.on_envelope Envelope.new(, future, Actor.current || Thread.current, self) return future ? future.with_hidden_resolvable : self end |
- (undocumented) name Originally defined in module PublicDelegations
- (undocumented) parent Originally defined in module PublicDelegations
- (undocumented) path Originally defined in module PublicDelegations
- (undocumented) reference Also known as: ref Originally defined in module PublicDelegations
- (Reference) tell(message) Also known as: <<
Sends the message asynchronously to the actor and immediately returns
self
(the reference) allowing to chain message telling.
32 33 34 |
# File 'lib/concurrent/actor/reference.rb', line 32 def tell() , nil end |
- (undocumented) to_s Also known as: inspect
91 92 93 |
# File 'lib/concurrent/actor/reference.rb', line 91 def to_s "#<#{self.class}:0x#{'%x' % (object_id << 1)} #{path} (#{actor_class})>" end |