class Concurrent::Actor::Reference

{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') { -> message { puts message } }
# => #<Concurrent::Actor::Reference:0x7fd0d2883218 /printer (Concurrent::Actor::Utils::AdHoc)>
#                                   ^object_id     ^path     ^context class

Attributes

core[R]

Public Class Methods

new(core) click to toggle source

@!visibility private

# File lib/concurrent/actor/reference.rb, line 19
def initialize(core)
  @core = Type! core, Core
end

Public Instance Methods

<<(message)
Alias for: tell
==(other) click to toggle source
# File lib/concurrent/actor/reference.rb, line 97
def ==(other)
  Type? other, self.class and other.send(:core) == core
end
ask(message, future = Concurrent.future) click to toggle source

@note 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_io_executor will block on while asking. It's fine to use it form outside of actors and global_io_executor.

@note 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.

@param [Object] message @param [Edge::Future] future to be fulfilled be message's processing result @return [Edge::Future] supplied future @example

adder = AdHoc.spawn('adder') { -> message { message + 1 } }
adder.ask(1).value # => 2
adder.ask(nil).wait.reason # => #<NoMethodError: undefined method `+' for nil:NilClass>
# File lib/concurrent/actor/reference.rb, line 54
def ask(message, future = Concurrent.future)
  message message, future
end
ask!(message, future = Concurrent.future) click to toggle source

Sends the message synchronously and blocks until the message is processed. Raises on error.

@note 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.

@param [Object] message @param [Edge::Future] future to be fulfilled be message's processing result @return [Object] message's processing result @raise [Exception] future.reason if future is failed? @example

adder = AdHoc.spawn('adder') { -> message { message + 1 } }
adder.ask!(1) # => 2
# File lib/concurrent/actor/reference.rb, line 72
def ask!(message, future = Concurrent.future)
  ask(message, future).value!
end
dead_letter_routing() click to toggle source

@see Concurrent::Actor::AbstractContext#dead_letter_routing

# File lib/concurrent/actor/reference.rb, line 87
def dead_letter_routing
  core.dead_letter_routing
end
inspect()
Alias for: to_s
map(messages) click to toggle source
# File lib/concurrent/actor/reference.rb, line 76
def map(messages)
  messages.map { |m| self.ask(m) }
end
message(message, future = nil) click to toggle source

behaves as {#tell} when no future and as {#ask} when future

# File lib/concurrent/actor/reference.rb, line 81
def message(message, future = nil)
  core.on_envelope Envelope.new(message, future, Actor.current || Thread.current, self)
  return future ? future.hide_completable : self
end
tell(message) click to toggle source

Sends the message asynchronously to the actor and immediately returns `self` (the reference) allowing to chain message telling. @param [Object] message @return [Reference] self @example

printer = AdHoc.spawn('printer') { -> message { puts message } }
printer.tell('ping').tell('pong')
printer << 'ping' << 'pong'
# => 'ping'\n'pong'\n'ping'\n'pong'\n
# File lib/concurrent/actor/reference.rb, line 32
def tell(message)
  message message, nil
end
Also aliased as: <<
to_s() click to toggle source
# File lib/concurrent/actor/reference.rb, line 91
def to_s
  "#<#{self.class}:0x#{'%x' % (object_id << 1)} #{path} (#{actor_class})>"
end
Also aliased as: inspect