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

Returns a new instance of PollUntil.



42
43
44
# File 'lib/roby/coordination/script.rb', line 42

def initialize(root_task, event, block)
    @root_task, @event, @block = root_task, event, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



41
42
43
# File 'lib/roby/coordination/script.rb', line 41

def block
  @block
end

#eventObject (readonly)

Returns the value of attribute event.



41
42
43
# File 'lib/roby/coordination/script.rb', line 41

def event
  @event
end

#root_taskObject (readonly)

Returns the value of attribute root_task.



41
42
43
# File 'lib/roby/coordination/script.rb', line 41

def root_task
  @root_task
end

Instance Method Details

#cancelObject



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

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

#execute(script) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/roby/coordination/script.rb', line 53

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

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

    false
end