Class: Dynflow::MicroActor

Inherits:
Object
  • Object
show all
Includes:
Algebrick::Matching, Algebrick::TypeCheck
Defined in:
lib/dynflow/micro_actor.rb

Constant Summary collapse

Terminate =
Algebrick.atom

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, *args) ⇒ MicroActor

Returns a new instance of MicroActor.



10
11
12
13
14
15
# File 'lib/dynflow/micro_actor.rb', line 10

def initialize(logger, *args)
  @logger      = logger
  @initialized = Future.new
  @thread      = Thread.new { run *args }
  Thread.pass until @mailbox
end

Instance Attribute Details

#initializedObject (readonly)

Returns the value of attribute initialized.



6
7
8
# File 'lib/dynflow/micro_actor.rb', line 6

def initialized
  @initialized
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/dynflow/micro_actor.rb', line 6

def logger
  @logger
end

Instance Method Details

#<<(message) ⇒ Object



17
18
19
20
21
# File 'lib/dynflow/micro_actor.rb', line 17

def <<(message)
  raise 'actor terminated' if terminated?
  @mailbox << [message, nil]
  self
end

#ask(message, future = Future.new) ⇒ Object



23
24
25
26
27
# File 'lib/dynflow/micro_actor.rb', line 23

def ask(message, future = Future.new)
  future.fail Dynflow::Error.new('actor terminated') if terminated?
  @mailbox << [message, future]
  future
end

#stopped?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dynflow/micro_actor.rb', line 29

def stopped?
  @terminated.ready?
end