lib/openwfe/expressions/fe_sequence.rb in ruote-0.9.18 vs lib/openwfe/expressions/fe_sequence.rb in ruote-0.9.19
- old
+ new
@@ -40,78 +40,88 @@
require 'openwfe/expressions/flowexpression'
module OpenWFE
- #
- # This expression sequentially executes each of its children expression.
- # For a more sophisticated version of it, see the 'cursor' expression
- # (fe_cursor.rb).
- #
- # <sequence>
- # <participant ref="alice" />
- # <participant ref="service_b" />
- # </sequence>
- #
- # In a Ruby process definition, it looks like :
- #
- # sequence do
- # participant "alice"
- # participant "service_b"
- # end
- #
- class SequenceExpression < FlowExpression
+ #
+ # This expression sequentially executes each of its children expression.
+ # For a more sophisticated version of it, see the 'cursor' expression
+ # (fe_cursor.rb).
+ #
+ # <sequence>
+ # <participant ref="alice" />
+ # <participant ref="service_b" />
+ # </sequence>
+ #
+ # In a Ruby process definition, it looks like :
+ #
+ # sequence do
+ # participant "alice"
+ # participant "service_b"
+ # end
+ #
+ class SequenceExpression < FlowExpression
- names :sequence
+ names :sequence
- def apply (workitem)
+ def apply (workitem)
- reply workitem
- end
+ reply workitem
+ end
- def reply (workitem)
+ def reply (workitem)
- cfei = next_child workitem.fei
+ cfei = next_child workitem.fei
- return reply_to_parent(workitem) \
- unless cfei
+ return reply_to_parent(workitem) \
+ unless cfei
- #ldebug do
- # "reply() self : \n#{self.to_s}\n" +
- # "reply() next is #{@current_child_id} : #{cfei.to_debug_s}"
- #end
+ #ldebug do
+ # "reply() self : \n#{self.to_s}\n" +
+ # "reply() next is #{@current_child_id} : #{cfei.to_debug_s}"
+ #end
- get_expression_pool.apply cfei, workitem
- end
+ get_expression_pool.apply cfei, workitem
+ end
- protected
+ protected
+ #
+ # Returns the flowExpressionId of the next child to apply, or
+ # nil if the sequence is over.
+ #
+ def next_child (current_fei)
+
+ # using @current_id as 'memo' of the current position
+
+ @current_id = nil \
+ if @current_id and (@children[@current_id] != current_fei)
#
- # Returns the flowExpressionId of the next child to apply, or
- # nil if the sequence is over.
- #
- def next_child (current_fei)
+ # the list of children changed, forget the current position
+ # will have to redetermine it ...
- next_id = if (current_fei == self.fei)
- 0
- else
- @children.index(current_fei) + 1
- end
+ @current_id = if @current_id
+ @current_id + 1
+ elsif current_fei == self.fei
+ 0
+ else
+ @children.index(current_fei) + 1
+ end
- loop do
+ loop do
- break if next_id >= @children.length
+ break if @current_id >= @children.length
- child = @children[next_id]
+ child = @children[@current_id]
- return child if child.is_a?(FlowExpressionId)
+ return child if child.is_a?(FlowExpressionId)
- next_id += 1
- end
+ @current_id += 1
+ end
- nil
- end
- end
+ nil
+ end
+ end
end