Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added withDeadline modifier #7299

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion hal/generate_usage_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe it was something that came up when attempting to merge from main

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to have been a weird interaction between the merge and the formatting. Just manually add the line back to clean up the PR diff.

import argparse
from pathlib import Path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ public SequentialCommandGroup andThen(Command... next) {
return group;
}

/**
* Creates a new command that runs this command and the deadline in parallel, finishing when the
* deadline finishes.
*
* <p>Note: This decorator works by adding this command to a composition. The command the
* decorator was called on cannot be scheduled independently or be added to a different
* composition (namely, decorators), unless it is manually cleared from the list of composed
* commands with {@link CommandScheduler#removeComposedCommand(Command)}. The command composition
* returned from this method can be further decorated without issue.
*
* @param deadline the deadline of the command group
* @return the decorated command
*/
public ParallelDeadlineGroup withDeadline(Command deadline) {
return new ParallelDeadlineGroup(deadline, this);
}

/**
* Decorates this command with a set of commands to run parallel to it, ending when the calling
* command ends and interrupting all the others. Often more convenient/less-verbose than
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ CommandPtr Command::OnlyIf(std::function<bool()> condition) && {
return std::move(*this).ToPtr().OnlyIf(std::move(condition));
}

CommandPtr Command::WithDeadline(CommandPtr&& deadline) && {
return std::move(*this).ToPtr().WithDeadline(std::move(deadline));
}

CommandPtr Command::DeadlineFor(CommandPtr&& parallel) && {
return std::move(*this).ToPtr().DeadlineFor(std::move(parallel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ CommandPtr CommandPtr::OnlyIf(std::function<bool()> condition) && {
return std::move(*this).Unless(std::not_fn(std::move(condition)));
}

CommandPtr CommandPtr::WithDeadline(CommandPtr&& deadline) && {
AssertValid();
std::vector<std::unique_ptr<Command>> vec;
vec.emplace_back(std::move(m_ptr));
m_ptr = std::make_unique<ParallelDeadlineGroup>(std::move(deadline).Unwrap(),
std::move(vec));
return std::move(*this);
}

CommandPtr CommandPtr::DeadlineWith(CommandPtr&& parallel) && {
AssertValid();
std::vector<std::unique_ptr<Command>> vec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
[[nodiscard]]
CommandPtr OnlyIf(std::function<bool()> condition) &&;

/**
* Creates a new command that runs this command
* and the deadline in parallel, finishing when
* the deadline finishes.
*
* @param deadline the deadline of the command group
* @return the decorated command
*/
Comment on lines +312 to +319
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: Do we want to include an explicit note that the calling command will be interrupted when the other command finishes? (This would make it match more with DeadlineFor)
Also, do we want to add @see DeadlineFor to the WithDeadline() doc comment and @see WithDeadline to the DeadlineFor doc comment?

(Both of these apply to Java, by the way)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense; i'll get around to it soon

CommandPtr WithDeadline(CommandPtr&& deadline) &&;

/**
* Decorates this command with a set of commands to run parallel to it, ending
* when the calling command ends and interrupting all the others. Often more
Expand All @@ -321,6 +331,7 @@ class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
*/
[[nodiscard]]
CommandPtr DeadlineFor(CommandPtr&& parallel) &&;

/**
* Decorates this command with a set of commands to run parallel to it, ending
* when the last command ends. Often more convenient/less-verbose than
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ class CommandPtr final {
[[nodiscard]]
CommandPtr OnlyIf(std::function<bool()> condition) &&;

/**
* Creates a new command that runs this command
* and the deadline in parallel, finishing when
* the deadline finishes.
*
* @param deadline the deadline of the command group
* @return the decorated command
*/
CommandPtr WithDeadline(CommandPtr&& deadline) &&;

/**
* Decorates this command with a set of commands to run parallel to it, ending
* when the calling command ends and interrupting all the others. Often more
Expand Down
Loading