class Concurrent::ErlangActor::Pid
The public reference of the actor which can be stored and passed around. Nothing else of the actor should be exposed. {Functions.spawn_actor} and {Environment#spawn} return the pid.
Public Class Methods
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 125 def initialize(actor, name) @Actor = actor @Name = name end
Public Instance Methods
The actor is asked the message and blocks until a reply is available, which is returned by the method. If the reply is a rejection then the methods raises it.
If the actor does not call {Environment#reply} or {Environment#reply_resolution} the method will raise NoReply
error. If the actor is terminated it will raise NoActor
. Therefore the ask is never left unanswered and blocking.
@param [Object] message @param [Numeric] timeout the maximum time in second to wait @param [Object] timeout_value the value returned on timeout @return [Object, timeout_value] reply to the message @raise [NoReply, NoActor]
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 77 def ask(message, timeout = nil, timeout_value = nil) @Actor.ask message, timeout, timeout_value end
Same as {#tell} but represented as a {Promises::Future}. @param [Object] message @param [Promises::ResolvableFuture] probe
a resolvable future which is resolved with the reply.
@return [Promises::Future(Object)] reply to the message
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 86 def ask_op(message, probe = Promises.resolvable_future) @Actor.ask_op message, probe end
@return [#to_s, nil] optional name of the actor
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 99 def name @Name end
The actor is asynchronously told a message. The method returns immediately unless the actor has bounded mailbox and there is no more space for the message. Then the method blocks current thread until there is space available. This is useful for backpressure.
@param [Object] message @param [Numeric] timeout the maximum time in second to wait @return [self, true, false]
self if timeout was nil, false on timing out and true if told in time.
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 52 def tell(message, timeout = nil) @Actor.tell message, timeout end
Same as {#tell} but represented as a {Promises::Future}. @param [Object] message @return [Promises::Future(self)]
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 59 def tell_op(message) @Actor.tell_op(message) end
@!macro erlang_actor.terminated
@return [Promises::Future] a future which is resolved with the final result of the actor that is either the reason for termination or a value if terminated normally.
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 94 def terminated @Actor.terminated end
@return [String] string representation
# File lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb, line 104 def to_s original = super state = case terminated.state when :pending 'running' when :fulfilled "terminated normally with #{terminated.value}" when :rejected "terminated because of #{terminated.reason}" else raise end [original[0..-2], *@Name, state].join(' ') << '>' end