Module: Concurrent::Actress::Context

Includes:
CoreDelegations, TypeCheck
Included in:
AdHoc, Root
Defined in:
lib/concurrent/actress/context.rb

Overview

module used to define actor behaviours

Examples:

ping

class Ping
  include Context
  def on_message(message)
    message
  end
end

Ping.spawn(:ping1).ask(:m).value #=> :m

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

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 Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



18
19
20
# File 'lib/concurrent/actress/context.rb', line 18

def core
  @core
end

Instance Method Details

#childrenObject



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

def children
  core.children
end

#loggerObject



29
30
31
# File 'lib/concurrent/actress/context.rb', line 29

def logger
  core.logger
end

#on_envelope(envelope) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
39
# File 'lib/concurrent/actress/context.rb', line 34

def on_envelope(envelope)
  @envelope = envelope
  on_message envelope.message
ensure
  @envelope = nil
end

#on_message(message) ⇒ Object

This method is abstract.

override to define Actor’s behaviour

Note:

self should not be returned (or sent to other actors), Concurrent::Actress::CoreDelegations#reference should be used instead

Returns a result which will be used to set the IVar supplied to Reference#ask.

Parameters:

  • message (Object)

Returns:

  • (Object)

    a result which will be used to set the IVar supplied to Reference#ask

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/concurrent/actress/context.rb', line 25

def on_message(message)
  raise NotImplementedError
end

#spawn(*args, &block) ⇒ Object



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

def spawn(*args, &block)
  Actress.spawn(*args, &block)
end

#terminate!Object



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

def terminate!
  core.terminate!
end