Module: Delayer::Deferred::Deferredable::NodeSequence

Included in:
Chain::Base, Chainable, Trigger
Defined in:
lib/delayer/deferred/deferredable/node_sequence.rb

Defined Under Namespace

Classes: Sequence

Constant Summary collapse

FRESH =
Sequence.new(:fresh)
CONNECTED =

子がいる、未実行

Sequence.new(:connected)
RESERVED =

実行キュー待ち

Sequence.new(:reserved)
RESERVED_C =

実行キュー待ち(子がいる)

Sequence.new(:reserved)
RUN =

実行中

Sequence.new(:run)
RUN_C =

実行中(子がいる)

Sequence.new(:run)
PASS =

パス中

Sequence.new(:pass)
PASS_C =

パス中

Sequence.new(:pass)
AWAIT =

Await中

Sequence.new(:await)
AWAIT_C =

Await中(子がいる)

Sequence.new(:await)
GRAFT =

戻り値がAwaitableの時

Sequence.new(:graft)
GRAFT_C =

戻り値がAwaitableの時(子がいる)

Sequence.new(:graft)
CALL_CHILD =

完了、子がいる

Sequence.new(:call_child)
STOP =

完了、子なし

Sequence.new(:stop)
WAIT =

完了、オブザーバ登録済み

Sequence.new(:wait)
BURST_OUT =

完了、オブザーバ登録済み、子追加済み

Sequence.new(:burst_out)
ROTTEN =

終了

Sequence.new(:rotten).freeze
GENOCIDE =

この地ではかつて大量虐殺があったという。

Sequence.new(:genocide).freeze
SEQUENCE_LOCK =
Monitor.new

Instance Method Summary collapse

Instance Method Details

#activated?Boolean

Returns:

  • (Boolean)

150
151
152
# File 'lib/delayer/deferred/deferredable/node_sequence.rb', line 150

def activated?
  ![FRESH, CONNECTED, RUN, RUN_C].include?(sequence)
end

#change_sequence(flow, &block) ⇒ Object

このメソッドはスレッドセーフです


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/delayer/deferred/deferredable/node_sequence.rb', line 131

def change_sequence(flow, &block)
  SEQUENCE_LOCK.synchronize do
    old_seq = sequence
    new_seq = @sequence = sequence.pull(flow)
    (@seq_logger ||= [old_seq]) << new_seq
    if block
      result = block.()
      on_sequence_changed(old_seq, flow, new_seq)
      result
    else
      on_sequence_changed(old_seq, flow, new_seq)
      nil
    end
  end
end

#on_sequence_changed(old_seq, flow, new_seq) ⇒ Object


147
148
# File 'lib/delayer/deferred/deferredable/node_sequence.rb', line 147

def on_sequence_changed(old_seq, flow, new_seq)
end

#sequenceObject


126
127
128
# File 'lib/delayer/deferred/deferredable/node_sequence.rb', line 126

def sequence
  @sequence ||= FRESH
end

#spoiled?Boolean

Returns:

  • (Boolean)

154
155
156
# File 'lib/delayer/deferred/deferredable/node_sequence.rb', line 154

def spoiled?
  sequence == ROTTEN || sequence == GENOCIDE
end