Class: Roby::Coordination::Script::PollUntil

Inherits:
Roby::Coordination::ScriptInstruction show all
Defined in:
lib/roby/coordination/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_task, event, block) ⇒ PollUntil



51
52
53
54
55
56
57
# File 'lib/roby/coordination/script.rb', line 51

def initialize(root_task, event, block)
    super()

    @root_task = root_task
    @event = event
    @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



49
50
51
# File 'lib/roby/coordination/script.rb', line 49

def block
  @block
end

#eventObject (readonly)

Returns the value of attribute event.



49
50
51
# File 'lib/roby/coordination/script.rb', line 49

def event
  @event
end

#root_taskObject (readonly)

Returns the value of attribute root_task.



49
50
51
# File 'lib/roby/coordination/script.rb', line 49

def root_task
  @root_task
end

Instance Method Details

#cancelObject



59
60
61
62
# File 'lib/roby/coordination/script.rb', line 59

def cancel
    root_task.remove_poll_handler(@poll_handler_id) if @poll_handler_id
    super
end

#execute(script) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/roby/coordination/script.rb', line 64

def execute(script)
    @poll_handler_id = root_task.poll do
        root_task.instance_eval(&block)
    end
    event = self.event.resolve
    event.once(on_replace: :copy) do |ev|
        if !disabled? && ev.generator == self.event.resolve
            cancel
            script.step
        end
    end

    root_task = script.root_task
    event_task = event.task
    if (event_task != root_task) && !root_task.depends_on?(event_task)
        root_task.depends_on event_task, success: event.symbol
    else
        event.when_unreachable(true) do |reason, _generator|
            unless disabled?
                raise Script::DeadInstruction.new(script.root_task),
                      "the 'until' condition of #{self} will "\
                      "never be reached: #{reason}"
            end
        end
    end

    false
end