Class: Delayer::Deferred::Promise

Inherits:
Object
  • Object
show all
Extended by:
Tools
Includes:
Deferredable::Trigger
Defined in:
lib/delayer/deferred/promise.rb

Constant Summary

Constants included from Deferredable::NodeSequence

Deferredable::NodeSequence::AWAIT, Deferredable::NodeSequence::AWAIT_C, Deferredable::NodeSequence::BURST_OUT, Deferredable::NodeSequence::CALL_CHILD, Deferredable::NodeSequence::CONNECTED, Deferredable::NodeSequence::FRESH, Deferredable::NodeSequence::GENOCIDE, Deferredable::NodeSequence::GRAFT, Deferredable::NodeSequence::GRAFT_C, Deferredable::NodeSequence::PASS, Deferredable::NodeSequence::PASS_C, Deferredable::NodeSequence::RESERVED, Deferredable::NodeSequence::RESERVED_C, Deferredable::NodeSequence::ROTTEN, Deferredable::NodeSequence::RUN, Deferredable::NodeSequence::RUN_C, Deferredable::NodeSequence::SEQUENCE_LOCK, Deferredable::NodeSequence::STOP, Deferredable::NodeSequence::WAIT

Instance Attribute Summary

Attributes included from Deferredable::Chainable

#child

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tools

fail, next, pass, sleep, system, trap, when

Methods included from Deferredable::Trigger

#call, #fail

Methods included from Deferredable::Chainable

#add_awaited, #add_child, #add_child_observer, #awaited, #cancel, #enter_pass, #exit_pass, #has_awaited?, #has_child?, #next, #reserve_activate, #trap

Methods included from Deferredable::NodeSequence

#activated?, #change_sequence, #on_sequence_changed, #sequence, #spoiled?

Methods included from Deferredable::Graph

#graph, #graph_child, #graph_draw, #graph_save

Methods included from Deferredable::Awaitable

#[email protected], #enter_await, #exit_await

Constructor Details

#initialize(name:) ⇒ Promise

Returns a new instance of Promise.


45
46
47
48
# File 'lib/delayer/deferred/promise.rb', line 45

def initialize(name:)
  super()
  @name = name
end

Class Method Details

.delayerObject


25
26
27
# File 'lib/delayer/deferred/promise.rb', line 25

def delayer
  ::Delayer
end

.new(stop = false, name: caller_locations(1,1).first.to_s, &block) ⇒ Object


11
12
13
14
15
16
# File 'lib/delayer/deferred/promise.rb', line 11

def new(stop=false, name: caller_locations(1,1).first.to_s, &block)
  result = promise = super(name: name)
  result = promise.next(&block) if block_given?
  promise.call(true) unless stop
  result
end

.PromiseObject


21
22
23
# File 'lib/delayer/deferred/promise.rb', line 21

def Promise
  self
end

.ThreadObject


18
19
# File 'lib/delayer/deferred/promise.rb', line 18

def Thread
@thread_class ||= gen_thread_class end

.to_sObject


29
30
31
# File 'lib/delayer/deferred/promise.rb', line 29

def to_s
  "#{self.delayer}.Promise"
end

Instance Method Details

#activate(response) ⇒ Object


50
51
52
53
54
# File 'lib/delayer/deferred/promise.rb', line 50

def activate(response)
  change_sequence(:activate)
  change_sequence(:complete)
  response
end

#ancestorObject


60
61
62
# File 'lib/delayer/deferred/promise.rb', line 60

def ancestor
  self
end

#inspectObject


56
57
58
# File 'lib/delayer/deferred/promise.rb', line 56

def inspect
  "#<#{self.class} seq:#{sequence.name}>"
end

#parent=(chainable) ⇒ Object


64
65
66
# File 'lib/delayer/deferred/promise.rb', line 64

def parent=(chainable)
  fail Error, "#{self.class} can't has parent."
end