123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::ErlangActor::Pid

Overview

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.

Class Attribute Summary

Class Method Summary

Synchronization::Object - Inherited

.atomic_attribute?, .atomic_attributes,
.attr_atomic

Creates methods for reading and writing to a instance variable with volatile (Java) semantic as .attr_volatile does.

.attr_volatile

Creates methods for reading and writing (as attr_accessor does) to a instance variable with volatile (Java) semantic.

.ensure_safe_initialization_when_final_fields_are_present

For testing purposes, quite slow.

.new

Has to be called by children.

.safe_initialization!, .define_initialize_atomic_fields

Synchronization::AbstractObject - Inherited

Instance Method Summary

Constructor Details

.new(actor, name) ⇒ Pid (private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 129

def initialize(actor, name)
  @Actor = actor
  @Name  = name
end

Instance Method Details

#ask(message, timeout = nil, timeout_value = nil) ⇒ Object, timeout_value

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.

Parameters:

  • message (Object)
  • timeout (Numeric) (defaults to: nil)

    the maximum time in second to wait

  • timeout_value (Object) (defaults to: nil)

    the value returned on timeout

Returns:

  • (Object, timeout_value)

    reply to the message

Raises:

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 81

def ask(message, timeout = nil, timeout_value = nil)
  @Actor.ask message, timeout, timeout_value
end

#ask_op(message, probe = Promises.resolvable_future) ⇒ Promises::Future(Object)

Same as #tell but represented as a Promises::Future.

Parameters:

Returns:

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 90

def ask_op(message, probe = Promises.resolvable_future)
  @Actor.ask_op message, probe
end

#inspect

Alias for #to_s.

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 123

alias_method :inspect, :to_s

#name ⇒ #to_s?

Returns:

  • (#to_s, nil)

    optional name of the actor

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 103

def name
  @Name
end

#tell(message, timeout = nil) ⇒ self, ...

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.

Parameters:

  • message (Object)
  • timeout (Numeric) (defaults to: nil)

    the maximum time in second to wait

Returns:

  • (self, true, false)

    self if timeout was nil, false on timing out and true if told in time.

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 56

def tell(message, timeout = nil)
  @Actor.tell message, timeout
end

#tell_op(message) ⇒ Promises::Future(self)

Same as #tell but represented as a Promises::Future.

Parameters:

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 63

def tell_op(message)
  @Actor.tell_op(message)
end

#terminatedPromises::Future

Returns:

  • (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.

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 98

def terminated
  @Actor.terminated
end

#to_sString Also known as: #inspect

Returns:

  • (String)

    string representation

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/edge/erlang_actor.rb', line 108

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