Skip to content

Commit

Permalink
[commands] Undeprecate deferredProxy (#7417)
Browse files Browse the repository at this point in the history
This changes the way deferred proxy is implemented to not use the
deprecated ProxyCommand constructor.

This function serves a good purpose that should be kept IMO. The
constructor was confusing but this is just good syntactic sugar over
`defer(() -> supplier.get().asProxy())`.

Signed-off-by: Jade Turner <[email protected]>
  • Loading branch information
spacey-sooty authored Jan 1, 2025
1 parent ce60bd5 commit 9ebc4b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,11 @@ public static Command defer(Supplier<Command> supplier, Set<Subsystem> requireme
*
* @param supplier the command supplier
* @return the command
* @deprecated The ProxyCommand supplier constructor has been deprecated in favor of directly
* proxying a {@link DeferredCommand}, see ProxyCommand documentation for more details. As a
* replacement, consider using `defer(supplier).asProxy()`.
* @see ProxyCommand
* @see DeferredCommand
*/
@Deprecated(since = "2025", forRemoval = true)
@SuppressWarnings("removal")
public static Command deferredProxy(Supplier<Command> supplier) {
return new ProxyCommand(supplier);
return defer(() -> supplier.get().asProxy(), Set.of());
}

// Command Groups
Expand Down
15 changes: 11 additions & 4 deletions wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>
#include <vector>

#include <wpi/FunctionExtras.h>
#include <wpi/deprecated.h>

#include "frc2/command/ConditionalCommand.h"
Expand Down Expand Up @@ -73,15 +74,21 @@ CommandPtr cmd::Print(std::string_view msg) {
return PrintCommand(msg).ToPtr();
}

WPI_IGNORE_DEPRECATED
CommandPtr cmd::DeferredProxy(wpi::unique_function<Command*()> supplier) {
return ProxyCommand(std::move(supplier)).ToPtr();
return Defer(
[supplier = std::move(supplier)]() mutable {
// There is no non-owning version of AsProxy(), so use the non-owning
// ProxyCommand constructor instead.
return ProxyCommand{supplier()}.ToPtr();
},
{});
}

CommandPtr cmd::DeferredProxy(wpi::unique_function<CommandPtr()> supplier) {
return ProxyCommand(std::move(supplier)).ToPtr();
return Defer([supplier = std::move(
supplier)]() mutable { return supplier().AsProxy(); },
{});
}
WPI_UNIGNORE_DEPRECATED

CommandPtr cmd::Wait(units::second_t duration) {
return WaitCommand(duration).ToPtr();
Expand Down
13 changes: 3 additions & 10 deletions wpilibNewCommands/src/main/native/include/frc2/command/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,11 @@ CommandPtr Defer(wpi::unique_function<CommandPtr()> supplier,
/**
* Constructs a command that schedules the command returned from the supplier
* when initialized, and ends when it is no longer scheduled. The supplier is
* called when the command is initialized. As a replacement, consider using
* `Defer(supplier).AsProxy()`.
* called when the command is initialized.
*
* @param supplier the command supplier
*/
WPI_IGNORE_DEPRECATED
[[nodiscard]] [[deprecated(
"The ProxyCommand supplier constructor has been deprecated. Use "
"Defer(supplier).AsProxy() instead.")]]
[[nodiscard]]
CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);

/**
Expand All @@ -187,11 +183,8 @@ CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);
*
* @param supplier the command supplier
*/
[[nodiscard]] [[deprecated(
"The ProxyCommand supplier constructor has been deprecated. Use "
"Defer(supplier).AsProxy() instead.")]]
[[nodiscard]]
CommandPtr DeferredProxy(wpi::unique_function<CommandPtr()> supplier);
WPI_UNIGNORE_DEPRECATED
// Command Groups

namespace impl {
Expand Down

0 comments on commit 9ebc4b3

Please sign in to comment.