Class: Concurrent::Actor::Utils::AdHoc

Inherits:
Context show all
Defined in:
lib/concurrent/actor/utils/ad_hoc.rb

Overview

Allows quick creation of actors with behaviour defined by blocks.

Examples:

ping

AdHoc.spawn :forward, an_actor do |where|
  # this block has to return proc defining #on_message behaviour
  -> message { where.tell message  }
end

Instance Attribute Summary

Attributes inherited from AbstractContext

#core

Instance Method Summary collapse

Methods inherited from Context

#behaviour_definition

Methods inherited from AbstractContext

#ask, #behaviour_definition, #dead_letter_routing, #default_reference_class, #envelope, #on_envelope, #on_event, #pass, #tell

Methods included from InternalDelegations

#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!

Methods included from PublicDelegations

#context_class, #executor, #name, #parent, #path, #reference

Methods included from TypeCheck

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

Constructor Details

#initialize(*args, &initializer) ⇒ AdHoc

Returns a new instance of AdHoc.



11
12
13
# File 'lib/concurrent/actor/utils/ad_hoc.rb', line 11

def initialize(*args, &initializer)
  @on_message = Type! initializer.call(*args), Proc
end

Instance Method Details

#on_message(message) ⇒ Object



15
16
17
# File 'lib/concurrent/actor/utils/ad_hoc.rb', line 15

def on_message(message)
  instance_exec message, &@on_message
end