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 = Hash.new) ⇒ 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 = Hash.new) ⇒ 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
274 275 276 277 278 279 |
# File 'lib/roby/coordination/models/script.rb', line 274 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
258 259 260 |
# File 'lib/roby/coordination/models/script.rb', line 258 def call(script) instructions.concat(script.instructions) end |
#emit(event) ⇒ Object
Emit the given event
252 253 254 255 |
# File 'lib/roby/coordination/models/script.rb', line 252 def emit(event) validate_event event add Emit.new(event) end |
#execute(task, options = Hash.new) ⇒ Object
Starts the given task, and waits for it to successfully finish
211 212 213 214 215 |
# File 'lib/roby/coordination/models/script.rb', line 211 def execute(task, = Hash.new) task = validate_or_create_task task start(task, ) wait(task.success_event) end |
#instructions ⇒ Array
The list of instructions in this script
191 |
# File 'lib/roby/coordination/models/script.rb', line 191 attribute(:instructions) { Array.new } |
#sleep(time) ⇒ Object
Waits a certain amount of time before continuing
220 221 222 223 224 |
# File 'lib/roby/coordination/models/script.rb', line 220 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
199 200 201 202 203 |
# File 'lib/roby/coordination/models/script.rb', line 199 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
179 180 181 |
# File 'lib/roby/coordination/models/script.rb', line 179 def terminal __terminal(true) end |
#terminal? ⇒ Boolean
Returns if true, this script cannot get new instructions (a terminal instruction has been added).
185 186 187 |
# File 'lib/roby/coordination/models/script.rb', line 185 def terminal? __terminal end |
#timeout_start(delay, options = Hash.new) ⇒ Object
262 263 264 265 266 |
# File 'lib/roby/coordination/models/script.rb', line 262 def timeout_start(delay, = Hash.new) ins = TimeoutStart.new(delay, ) add ins ins end |
#timeout_stop(timeout_start) ⇒ Object
268 269 270 271 272 |
# File 'lib/roby/coordination/models/script.rb', line 268 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)
235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/roby/coordination/models/script.rb', line 235 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 |