Class: Concurrent::Actress::Reference

Inherits:
Object
  • Object
show all
Includes:
CoreDelegations, TypeCheck
Defined in:
lib/concurrent/actress/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 CoreDelegations

Instance Method Summary collapse

Methods included from CoreDelegations

#executor, #name, #parent, #path, #reference, #terminated, #terminated?

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?

Instance Method Details

#==(other) ⇒ Object



58
59
60
# File 'lib/concurrent/actress/reference.rb', line 58

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

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

tells message to the actor

Parameters:

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

    to be fulfilled be message’s processing result

Returns:

  • (IVar)

    supplied ivar



32
33
34
# File 'lib/concurrent/actress/reference.rb', line 32

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

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

Note:

can lead to deadlocks, use only in tests or when you are sure it won’t deadlock

tells message to the actor

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?



42
43
44
# File 'lib/concurrent/actress/reference.rb', line 42

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

#message(message, ivar = nil) ⇒ Object

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



47
48
49
50
# File 'lib/concurrent/actress/reference.rb', line 47

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

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

tells message to the actor

Parameters:

  • message (Object)

Returns:



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

def tell(message)
  message message, nil
end

#to_sObject Also known as: inspect



52
53
54
# File 'lib/concurrent/actress/reference.rb', line 52

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