mirror of
https://github.com/Team4388/2023WayOfTheRobot.git
synced 2026-06-09 08:38:02 -06:00
added deferred blocks
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package frc4388.utility;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DeferredBlock {
|
||||
private static ArrayList<Runnable> m_blocks = new ArrayList<>();
|
||||
private static boolean m_hasRun = false;
|
||||
|
||||
public DeferredBlock(Runnable block) {
|
||||
m_blocks.add(block);
|
||||
}
|
||||
|
||||
public static void execute() {
|
||||
if (m_hasRun) return;
|
||||
|
||||
for (Runnable block : m_blocks) {
|
||||
block.run();
|
||||
}
|
||||
|
||||
m_blocks.clear(); // for garbage collection
|
||||
m_hasRun = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user