Class: Ruote::Exp::LoseExpression

Inherits:
FlowExpression show all
Defined in:
lib/ruote/exp/fe_lose.rb

Overview

Never replies to its parent expression. Simply applies its first child, if any, and just sits there.

When cancelled, cancels its child (if any).

In this example, the reminding sequence never replies to the concurrence. The concurrence is only over when “alfred” replies.

Ruote.process_definition do
  concurrence :count => 1 do
    alfred
    lose do
      sequence do
        wait '2d'
        send_reminder_to_alfred
        wait '2h'
        send_alarm_to_boss
      end
    end
  end
end

Maybe shorter :

Ruote.process_definition do
  concurrence :count => 1 do
    alfred
    sequence do
      wait '2d'
      send_reminder_to_alfred
      wait '2h'
      send_alarm_to_boss
      lose
    end
  end
end

‘lose’ on its own acts like a dead-end.

the :lose attribute

Every expression understands the ‘lose’ attribute :

Ruote.process_definition do
  concurrence :count => 1 do
    alfred
    sequence :lose => true do
      wait '2d'
      send_reminder_to_alfred
      wait '2h'
      send_alarm_to_boss
    end
  end
end

Probably produces definitions more compact than when using the ‘lose’ expression.

multi lose

Losing multiple children:

lose do
  alice :task => 'take out garbage'
  bob :task => 'clean living room'
end

will trigger alice’s and bob’s tasks together. The lose expression will never reply, unless cancelled (in which case alice and bob task get cancelled as well).

forget vs lose vs flank

forget : replies to parent expression immediately, is not cancellable (not reachable).

lose : never replies to the parent expression, is cancellable.

flank : immediately replies to the parent expression, is cancellable.

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error, #h

Instance Method Summary collapse

Methods inherited from FlowExpression

#ancestor?, #applied_workitem, #att, #att_text, #attribute, #attribute_text, #attributes, #await, #cancel, #cancel_flanks, #cfei_at, #child_id, #child_ids, #compile_atts, #compile_variables, #debug_id, #deflate, #do, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_reply_to_parent, #do_resume, #do_unpersist, dummy, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #is_concurrent?, #iterative_var_lookup, #launch_sub, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #pause_on_apply, #persist_or_raise, #reply_to_parent, #root, #root_id, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables, #wfid

Methods included from WithMeta

#class_def, included

Methods included from WithH

included

Constructor Details

This class inherits a constructor from Ruote::Exp::FlowExpression

Instance Method Details

#applyObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ruote/exp/fe_lose.rb', line 116

def apply

  tree_children.each_with_index do |t, index|

    msg = pre_apply_child(index, Ruote.fulldup(h.applied_workitem), false)
      # forget ? false

    @context.storage.put_msg('apply', msg)
  end

  persist_or_raise

  # no reply to the parent expression
end

#reply(workitem) ⇒ Object



131
132
133
134
# File 'lib/ruote/exp/fe_lose.rb', line 131

def reply(workitem)

  # never gets called
end