Class: StateMachine::TimedTransition
- Inherits:
-
Transition
- Object
- Transition
- StateMachine::TimedTransition
- Defined in:
- lib/motion-state-machine/transition.rb
Overview
Transitions of this type are triggered on a given timeout (in seconds). Created when supplying an :after option in the transition definition.
The timeout is canceled when the state is left.
The transition uses Grand Central Dispatch’s timer source mechanism: It adds a timer source to the state machine’s initial GCD queue.
The system tries to achieve an accuracy of 1 millisecond for the timeout. You can change this behavior to trade timing accuracy vs. system performance by using the leeway
option (given in seconds). See Apple’s GCD documentation for more information about this parameter.
Instance Attribute Summary
Attributes inherited from Transition
#destination_state, #event_trigger_value, #options, #source_state, #state_machine
Instance Method Summary collapse
Methods inherited from Transition
#allowed?, #initialize, #inspect, make, types
Constructor Details
This class inherits a constructor from StateMachine::Transition
Instance Method Details
#arm ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/motion-state-machine/transition.rb', line 331 def arm @state_machine.log "Starting timeout -> #{[:to]}, "\ "after #{[:after]}" delay = event_trigger_value interval = 0 leeway = @options[:leeway] || 0.001 queue = @state_machine.initial_queue @timer = Dispatch::Source.timer(delay, interval, leeway, queue) do @state_machine.log "Timeout!" self.handle_in_source_state end end |
#event_description ⇒ Object
325 326 327 328 |
# File 'lib/motion-state-machine/transition.rb', line 325 def event_description "after #{event_trigger_value} seconds of "\ "#{source_state.name} (timeout)" end |
#unarm ⇒ Object
344 345 346 347 |
# File 'lib/motion-state-machine/transition.rb', line 344 def unarm @state_machine.log "Timer unarmed" @timer.cancel! end |