Class: Delayer::Deferred::Chain::Base

Inherits:
Object
  • Object
show all
Includes:
Deferredable::Chainable, Deferredable::NodeSequence
Defined in:
lib/delayer/deferred/chain/base.rb

Direct Known Subclasses

Await, Next, Trap

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

Instance Method Summary collapse

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

#+@, #enter_await, #exit_await

Constructor Details

#initialize(&proc) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/delayer/deferred/chain/base.rb', line 10

def initialize(&proc)
  fail Error, "Delayer::Deferred::Chain can't create instance." if self.class == Delayer::Deferred::Chain::Base
  @proc = proc
end

Instance Method Details

#activate(response) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/delayer/deferred/chain/base.rb', line 15

def activate(response)
  change_sequence(:activate)
  if evaluate?(response)
    @proc.(response.value)
  else
    response
  end
ensure
  change_sequence(:complete)
end

#inspectObject



26
27
28
# File 'lib/delayer/deferred/chain/base.rb', line 26

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

#node_nameObject



30
31
32
# File 'lib/delayer/deferred/chain/base.rb', line 30

def node_name
  @proc.source_location.join(':'.freeze)
end