Class: MrDarcy::Promise::Celluloid::Actor

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/mr_darcy/promise/celluloid.rb

Overview

Each promise gets it's own actor thread. :nodoc:

Instance Method Summary collapse

Constructor Details

#initializeActor


16
17
18
# File 'lib/mr_darcy/promise/celluloid.rb', line 16

def initialize
  @complete = false
end

Instance Method Details

#await_completionObject


43
44
45
46
# File 'lib/mr_darcy/promise/celluloid.rb', line 43

def await_completion
  return if @complete
  wait :complete
end

#on_failure(block) ⇒ Object


39
40
41
# File 'lib/mr_darcy/promise/celluloid.rb', line 39

def on_failure block
  @failure = block
end

#on_success(block) ⇒ Object


35
36
37
# File 'lib/mr_darcy/promise/celluloid.rb', line 35

def on_success block
  @success = block
end

#schedule(block) ⇒ Object


20
21
22
# File 'lib/mr_darcy/promise/celluloid.rb', line 20

def schedule block
  ::Celluloid::Future.new &block
end

#set_status(status, value) ⇒ Object


24
25
26
27
28
29
30
31
32
33
# File 'lib/mr_darcy/promise/celluloid.rb', line 24

def set_status status, value
  case status
  when :success
    @success.call value
  when :failure
    @failure.call value
  end
  signal :complete
  @complete = true
end