forked from robotpy/robotpy-commands-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxyschedulecommand.py
41 lines (32 loc) · 1.32 KB
/
proxyschedulecommand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
from .command import Command
from .commandgroup import *
class ProxyScheduleCommand(Command):
"""
Schedules the given commands when this command is initialized, and ends when all the commands are
no longer scheduled. Useful for forking off from CommandGroups. If this command is interrupted,
it will cancel all the commands.
"""
def __init__(self, *toSchedule: Command):
"""
Creates a new ProxyScheduleCommand that schedules the given commands when initialized, and ends
when they are all no longer scheduled.
:param toSchedule: the commands to schedule
@deprecated Replace with ProxyCommand, composing multiple of them in a {@link
ParallelRaceGroup} if needed."""
super().__init__()
self.toSchedule = set(toSchedule)
self._finished = False
def initialize(self):
for command in self.toSchedule:
command.schedule()
def end(self, interrupted: bool):
if interrupted:
for command in self.toSchedule:
command.cancel()
def execute(self):
self._finished = True
for command in self.toSchedule:
self._finished = self._finished and not command.isScheduled()
def isFinished(self) -> bool:
return self._finished