Skip to content

Commit c21b4cf

Browse files
committed
use Atomic Integer instead of array for refrence-passing.
1 parent b3b5be6 commit c21b4cf

File tree

1 file changed

+5
-2
lines changed
  • wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command

1 file changed

+5
-2
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Collection;
1616
import java.util.HashSet;
1717
import java.util.Set;
18+
import java.util.concurrent.atomic.AtomicInteger;
1819
import java.util.function.BooleanSupplier;
1920

2021
/**
@@ -400,8 +401,10 @@ public RepeatCommand repeatedly() {
400401
* @return the decorated command
401402
*/
402403
public ParallelRaceGroup repeatedly(int times) {
403-
int[] counter = {0};
404-
return this.finallyDo(() -> counter[0]++).repeatedly().until(() -> counter[0] >= times);
404+
AtomicInteger counter = new AtomicInteger(0);
405+
return this.finallyDo(counter::getAndIncrement)
406+
.repeatedly()
407+
.until(() -> counter.get() >= times);
405408
}
406409

407410
/**

0 commit comments

Comments
 (0)