Class: Concurrent::Actor::Reference

Inherits:
Object
  • Object
show all
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 program. It also provides some basic information about the actor, see PublicDelegations.

Instance Method Summary collapse

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



72
73
74
# File 'lib/concurrent/actor/reference.rb', line 72

def ==(other)
  Type? other, self.class and other.send(:core) == core
end

#ask(message, ivar = IVar.new) ⇒ IVar

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_task_pool will block on while asking. It’s fine to use it form outside of actors and global_task_pool.

sends message to the actor and asks for the result of its processing, returns immediately

Parameters:

  • message (Object)
  • ivar (Ivar) (defaults to: IVar.new)

    to be fulfilled be message’s processing result

Returns:

  • (IVar)

    supplied ivar



37
38
39
# File 'lib/concurrent/actor/reference.rb', line 37

def ask(message, ivar = IVar.new)
  message message, ivar
end

#ask!(message, ivar = IVar.new) ⇒ Object

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_task_pool will block on while asking. It’s fine to use it form outside of actors and global_task_pool.

sends message to the actor and asks for the result of its processing, blocks

Parameters:

  • message (Object)
  • ivar (Ivar) (defaults to: IVar.new)

    to be fulfilled be message’s processing result

Returns:

  • (Object)

    message’s processing result

Raises:

  • (Exception)

    ivar.reason if ivar is #rejected?



51
52
53
# File 'lib/concurrent/actor/reference.rb', line 51

def ask!(message, ivar = IVar.new)
  ask(message, ivar).value!
end

#dead_letter_routingObject



62
63
64
# File 'lib/concurrent/actor/reference.rb', line 62

def dead_letter_routing
  core.dead_letter_routing
end

#message(message, ivar = nil) ⇒ Object

behaves as #tell when no ivar and as #ask when ivar



56
57
58
59
# File 'lib/concurrent/actor/reference.rb', line 56

def message(message, ivar = nil)
  core.on_envelope Envelope.new(message, ivar, Actor.current || Thread.current, self)
  return ivar || self
end

#tell(message) ⇒ Reference Also known as: <<

tells message to the actor, returns immediately

Parameters:

  • message (Object)

Returns:



22
23
24
# File 'lib/concurrent/actor/reference.rb', line 22

def tell(message)
  message message, nil
end

#to_sObject Also known as: inspect



66
67
68
# File 'lib/concurrent/actor/reference.rb', line 66

def to_s
  "#<#{self.class} #{path} (#{actor_class})>"
end