Class: Roby::Coordination::Models::Script::Wait
- Inherits:
-
ScriptInstruction
- Object
- ScriptInstruction
- Roby::Coordination::Models::Script::Wait
- Defined in:
- lib/roby/coordination/models/script.rb
Overview
Script element that implements #wait
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#time_barrier ⇒ Time?
readonly
Time after which an emission is valid.
-
#timeout ⇒ Float
readonly
Number of seconds after which the wait instruction should generate an error.
Instance Method Summary collapse
-
#done? ⇒ Boolean
True if the watched event got emitted.
- #execute(script) ⇒ Object
-
#initialize(event, after: nil) ⇒ Wait
constructor
A new instance of Wait.
-
#initialized? ⇒ Boolean
True if #execute has been called once.
- #new(script) ⇒ Object
- #to_s ⇒ Object
- #waited_task_role ⇒ Object
Methods inherited from ScriptInstruction
Constructor Details
#initialize(event, after: nil) ⇒ Wait
Returns a new instance of Wait.
58 59 60 61 62 |
# File 'lib/roby/coordination/models/script.rb', line 58 def initialize(event, after: nil) @event = event @done = false = after end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
38 39 40 |
# File 'lib/roby/coordination/models/script.rb', line 38 def event @event end |
#time_barrier ⇒ Time? (readonly)
Returns time after which an emission is valid. ‘nil’ means that only emissions that have happened after the script reached this instruction are considered.
43 44 45 |
# File 'lib/roby/coordination/models/script.rb', line 43 def end |
#timeout ⇒ Float (readonly)
Returns number of seconds after which the wait instruction should generate an error.
47 48 49 |
# File 'lib/roby/coordination/models/script.rb', line 47 def timeout @timeout end |
Instance Method Details
#done? ⇒ Boolean
Returns true if the watched event got emitted.
53 |
# File 'lib/roby/coordination/models/script.rb', line 53 attr_predicate :done? |
#execute(script) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/roby/coordination/models/script.rb', line 68 def execute(script) event = self.event.resolve plan = script.plan root_task = script.root_task if last_event = event.history.last if last_event && last_event.time > return true end end if event.unreachable? plan.add_error(DeadInstruction.new(script.root_task)) return false end if event.task != root_task role_name = "wait_#{self.object_id}" current_roles = (root_task.depends_on?(event.task) && root_task.roles_of(event.task)) root_task.depends_on event.task, success: nil, role: role_name end event.if_unreachable(cancel_at_emission: true) do |reason, generator| if !disabled? generator.plan.add_error(DeadInstruction.new(script.root_task)) end end event.on on_replace: :copy do |event| if event.generator == self.event.resolve && !disabled? if ! || event.time > if role_name && (child = script.root_task.find_child_from_role(role_name)) script.root_task.remove_roles(child, role_name, remove_child_when_empty: !current_roles || !current_roles.empty?) end cancel script.step end end end false end |
#initialized? ⇒ Boolean
Returns true if #execute has been called once.
50 |
# File 'lib/roby/coordination/models/script.rb', line 50 attr_predicate :initialized? |
#new(script) ⇒ Object
64 65 66 |
# File 'lib/roby/coordination/models/script.rb', line 64 def new(script) Wait.new(script.instance_for(event), after: ) end |
#to_s ⇒ Object
116 |
# File 'lib/roby/coordination/models/script.rb', line 116 def to_s; "wait(#{event})" end |
#waited_task_role ⇒ Object
112 113 114 |
# File 'lib/roby/coordination/models/script.rb', line 112 def waited_task_role "wait_#{object_id}" end |