Skip to content

Commit

Permalink
Changed the composition to use beforeStarting
Browse files Browse the repository at this point in the history
  • Loading branch information
oh-yes-0-fps committed Sep 19, 2024
1 parent 8c1f052 commit 17ae89d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public ParallelRaceGroup onlyWhile(BooleanSupplier condition) {
public SequentialCommandGroup after(BooleanSupplier condition) {
// if we want this to bypass the `WaitUntilCommand` if the condition is already true,
// we can use a conditional command but it proposes some compositional issues
return new SequentialCommandGroup(new WaitUntilCommand(condition), this);
return beforeStarting(new WaitUntilCommand(condition));
}

/**
Expand All @@ -249,7 +249,7 @@ public SequentialCommandGroup after(BooleanSupplier condition) {
* @return the decorated command
*/
public SequentialCommandGroup afterSeconds(double seconds) {
return new SequentialCommandGroup(new WaitCommand(seconds), this);
return beforeStarting(new WaitCommand(seconds));
}

/**
Expand Down
12 changes: 2 additions & 10 deletions wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,12 @@ CommandPtr CommandPtr::OnlyIf(std::function<bool()> condition) && {

CommandPtr CommandPtr::After(std::function<bool()> condition) && {
AssertValid();
std::vector<std::unique_ptr<Command>> temp;
temp.emplace_back(std::make_unique<WaitUntilCommand>(std::move(condition)));
temp.emplace_back(std::move(m_ptr));
m_ptr = std::make_unique<SequentialCommandGroup>(std::move(temp));
return std::move(*this);
return std::move(*this).BeforeStarting(std::make_unique<WaitUntilCommand>(std::move(condition)));
}

CommandPtr CommandPtr::AfterTime(units::second_t duration) && {
AssertValid();
std::vector<std::unique_ptr<Command>> temp;
temp.emplace_back(std::make_unique<WaitCommand>(duration));
temp.emplace_back(std::move(m_ptr));
m_ptr = std::make_unique<SequentialCommandGroup>(std::move(temp));
return std::move(*this);
return std::move(*this).BeforeStarting(std::make_unique<WaitCommand>(duration));
}

CommandPtr CommandPtr::DeadlineWith(CommandPtr&& parallel) && {
Expand Down

0 comments on commit 17ae89d

Please sign in to comment.