Module: Roby::Coordination::Models::Script
- Extended by:
- MetaRuby::Attributes
- Included in:
- ActionScript, FaultHandler, TaskScript
- Defined in:
- lib/roby/coordination/models/script.rb
Overview
The metamodel for all script-based coordination models
Defined Under Namespace
Classes: DeadInstruction, Emit, Start, TimeoutStart, TimeoutStop, Wait
Instance Method Summary collapse
- #add(instruction) ⇒ Object
-
#call(script) ⇒ Object
Execute another script at this point in the execution.
-
#emit(event) ⇒ Object
Emit the given event.
-
#execute(task, **options) ⇒ Object
Starts the given task, and waits for it to successfully finish.
-
#instructions ⇒ Array
The list of instructions in this script.
-
#sleep(time) ⇒ Object
Waits a certain amount of time before continuing.
-
#start(task, explicit_start: false, **options) ⇒ Object
Starts the given task.
-
#terminal ⇒ Object
Marks this script has being terminated, i.e.
-
#terminal? ⇒ Boolean
If true, this script cannot get new instructions (a terminal instruction has been added).
- #timeout_start(delay, options = {}) ⇒ Object
- #timeout_stop(timeout_start) ⇒ Object
-
#wait(event, timeout: nil, **wait_options) ⇒ Object
Waits until this event gets emitted.
Instance Method Details
#add(instruction) ⇒ Object
312 313 314 315 316 317 318 |
# File 'lib/roby/coordination/models/script.rb', line 312 def add(instruction) if terminal? raise ArgumentError, "a terminal command has been called on this script, cannot add anything further" end instructions << instruction end |
#call(script) ⇒ Object
Execute another script at this point in the execution
296 297 298 |
# File 'lib/roby/coordination/models/script.rb', line 296 def call(script) instructions.concat(script.instructions) end |
#emit(event) ⇒ Object
Emit the given event
290 291 292 293 |
# File 'lib/roby/coordination/models/script.rb', line 290 def emit(event) validate_event event add Emit.new(event) end |
#execute(task, **options) ⇒ Object
Starts the given task, and waits for it to successfully finish
249 250 251 252 253 |
# File 'lib/roby/coordination/models/script.rb', line 249 def execute(task, **) task = validate_or_create_task task start(task, **) wait(task.success_event) end |
#instructions ⇒ Array
The list of instructions in this script
229 |
# File 'lib/roby/coordination/models/script.rb', line 229 attribute(:instructions) { [] } |
#sleep(time) ⇒ Object
Waits a certain amount of time before continuing
258 259 260 261 262 |
# File 'lib/roby/coordination/models/script.rb', line 258 def sleep(time) task = self.task(ActionCoordination::TaskFromAsPlan.new(Tasks::Timeout.with_arguments(delay: time), Tasks::Timeout)) start task, explicit_start: true wait task.stop_event end |
#start(task, explicit_start: false, **options) ⇒ Object
Starts the given task
237 238 239 240 241 |
# File 'lib/roby/coordination/models/script.rb', line 237 def start(task, explicit_start: false, **) task = validate_or_create_task task add Start.new(task, explicit_start: explicit_start, **) wait(task.start_event) end |
#terminal ⇒ Object
Marks this script has being terminated, i.e. that no new instructions can be added to it
Once this is called, adding new instructions will raise ArgumentError
217 218 219 |
# File 'lib/roby/coordination/models/script.rb', line 217 def terminal __terminal(true) end |
#terminal? ⇒ Boolean
Returns if true, this script cannot get new instructions (a terminal instruction has been added).
223 224 225 |
# File 'lib/roby/coordination/models/script.rb', line 223 def terminal? __terminal end |
#timeout_start(delay, options = {}) ⇒ Object
300 301 302 303 304 |
# File 'lib/roby/coordination/models/script.rb', line 300 def timeout_start(delay, = {}) ins = TimeoutStart.new(delay, ) add ins ins end |
#timeout_stop(timeout_start) ⇒ Object
306 307 308 309 310 |
# File 'lib/roby/coordination/models/script.rb', line 306 def timeout_stop(timeout_start) ins = TimeoutStop.new(timeout_start) add ins ins end |
#wait(event, timeout: nil, **wait_options) ⇒ Object
Waits until this event gets emitted
It will wait even if this event has already been emitted at this point in the script (i.e. waits for a “new” emission)
273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/roby/coordination/models/script.rb', line 273 def wait(event, timeout: nil, **) validate_event event wait = Wait.new(event, **) if timeout timeout(timeout) do add wait end else add wait end wait end |