added deferred blocks

This commit is contained in:
66945
2023-03-14 10:35:53 -06:00
parent 801619ef30
commit 2986103e9f
3 changed files with 35 additions and 1 deletions
@@ -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;
}
}