Skip to content

Commit 4380b8a

Browse files
committed
[cmd] Undeprecate deferredProxy
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]>
1 parent 0a3ccf9 commit 4380b8a

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,11 @@ public static Command defer(Supplier<Command> supplier, Set<Subsystem> requireme
198198
*
199199
* @param supplier the command supplier
200200
* @return the command
201-
* @deprecated The ProxyCommand supplier constructor has been deprecated in favor of directly
202-
* proxying a {@link DeferredCommand}, see ProxyCommand documentation for more details. As a
203-
* replacement, consider using `defer(supplier).asProxy()`.
204201
* @see ProxyCommand
202+
* @see DeferredCommand
205203
*/
206-
@Deprecated(since = "2025", forRemoval = true)
207-
@SuppressWarnings("removal")
208204
public static Command deferredProxy(Supplier<Command> supplier) {
209-
return new ProxyCommand(supplier);
205+
return defer(() -> supplier.get().asProxy(), Set.of());
210206
}
211207

212208
// Command Groups

wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <utility>
88
#include <vector>
99

10+
#include <wpi/FunctionExtras.h>
1011
#include <wpi/deprecated.h>
1112

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

76-
WPI_IGNORE_DEPRECATED
7777
CommandPtr cmd::DeferredProxy(wpi::unique_function<Command*()> supplier) {
78-
return ProxyCommand(std::move(supplier)).ToPtr();
78+
return Defer(
79+
[supplier = std::move(supplier)]() mutable {
80+
// There is no non-owning version of AsProxy(), so use the non-owning
81+
// ProxyCommand constructor instead.
82+
return ProxyCommand{supplier()}.ToPtr();
83+
},
84+
{});
7985
}
8086

8187
CommandPtr cmd::DeferredProxy(wpi::unique_function<CommandPtr()> supplier) {
82-
return ProxyCommand(std::move(supplier)).ToPtr();
88+
return Defer([supplier = std::move(
89+
supplier)]() mutable { return supplier().AsProxy(); },
90+
{});
8391
}
84-
WPI_UNIGNORE_DEPRECATED
8592

8693
CommandPtr cmd::Wait(units::second_t duration) {
8794
return WaitCommand(duration).ToPtr();

wpilibNewCommands/src/main/native/include/frc2/command/Commands.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,11 @@ CommandPtr Defer(wpi::unique_function<CommandPtr()> supplier,
169169
/**
170170
* Constructs a command that schedules the command returned from the supplier
171171
* when initialized, and ends when it is no longer scheduled. The supplier is
172-
* called when the command is initialized. As a replacement, consider using
173-
* `Defer(supplier).AsProxy()`.
172+
* called when the command is initialized.
174173
*
175174
* @param supplier the command supplier
176175
*/
177-
WPI_IGNORE_DEPRECATED
178-
[[nodiscard]] [[deprecated(
179-
"The ProxyCommand supplier constructor has been deprecated. Use "
180-
"Defer(supplier).AsProxy() instead.")]]
176+
[[nodiscard]]
181177
CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);
182178

183179
/**
@@ -187,11 +183,8 @@ CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);
187183
*
188184
* @param supplier the command supplier
189185
*/
190-
[[nodiscard]] [[deprecated(
191-
"The ProxyCommand supplier constructor has been deprecated. Use "
192-
"Defer(supplier).AsProxy() instead.")]]
186+
[[nodiscard]]
193187
CommandPtr DeferredProxy(wpi::unique_function<CommandPtr()> supplier);
194-
WPI_UNIGNORE_DEPRECATED
195188
// Command Groups
196189

197190
namespace impl {

0 commit comments

Comments
 (0)