Skip to content

Commit

Permalink
Merge pull request #71 from narmstro2020/ScheduleDecorator
Browse files Browse the repository at this point in the history
[cmd] Add ScheduleCommand decorator
  • Loading branch information
virtuald authored Oct 19, 2024
2 parents 81f6129 + 511e7c1 commit 8006897
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions commands2/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,23 @@ def asProxy(self) -> ProxyCommand:
from .proxycommand import ProxyCommand

return ProxyCommand(self)

def fork(self, *commands: Command) -> ProxyCommand:
"""
Decorates this command to run "forked" by wrapping it in a ScheduleCommand. Use this for
"forking off" from command compositions when the user does not wish to extend the command's
requirements to the entire command composition. Note that if run from a composition, the
composition will not know about the status of the scheduled commands, and will treat this
command as finishing instantly. Commands can be added to this and will be scheduled in order
with this command scheduled first., see the `WPILib docs <https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands>`_ for a full explanation.
:param other: other commands to schedule along with this one. This command is scheduled first.
:returns: the decorated command
"""
from .schedulecommand import ScheduleCommand


return ScheduleCommand(self, [self] + commands)

Check failure on line 402 in commands2/command.py

View workflow job for this annotation

GitHub Actions / check-mypy

Incompatible return value type (got "ScheduleCommand", expected "ProxyCommand")

Check failure on line 402 in commands2/command.py

View workflow job for this annotation

GitHub Actions / check-mypy

No overload variant of "__add__" of "list" matches argument type "tuple[Command, ...]"

def unless(self, condition: Callable[[], bool]) -> ConditionalCommand:
"""
Expand Down

0 comments on commit 8006897

Please sign in to comment.