Skip to content

Commit

Permalink
Add startRun command factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchdukeTim committed May 1, 2024
1 parent 1d78b88 commit 138ded2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions commands2/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ def runEnd(
lambda: None, run, lambda interrupted: end(), lambda: False, *requirements
)

def startRun(
start: Callable[[], Any], run: Callable[[], Any], *requirements: Subsystem
) -> Command:
"""
Constructs a command that runs an action once and another action every iteration until interrupted.
:param start: the action to run on start
:param run: the action to run every iteration
:param requirements: subsystems the action requires
:returns: the command
"""
return FunctionalCommand(
start, run, lambda interrupt: None, lambda: False, *requirements
)

def print_(message: str) -> Command:
"""
Expand Down
12 changes: 12 additions & 0 deletions commands2/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ def runEnd(self, run: Callable[[], None], end: Callable[[], None]) -> Command:

return runEnd(run, end, self)

def startRun(self, start: Callable[[], None], run: Callable[[], None]) -> Command:
"""
Constructs a command that runs an action once and another action every iteration until interrupted. Requires this subsystem.
:param start: the action to run on start
:param run: the action to run every iteration
:returns: the command
"""
from .cmd import startRun

return startRun(start, run, self)

#
# From SubsystemBase
#
Expand Down

0 comments on commit 138ded2

Please sign in to comment.