001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj.event; 006 007import java.util.Collection; 008import java.util.LinkedHashSet; 009 010/** The loop polling {@link BooleanEvent} objects and executing the actions bound to them. */ 011public final class EventLoop { 012 private final Collection<Runnable> m_bindings = new LinkedHashSet<>(); 013 014 /** 015 * Bind a new action to run whenever the condition is true. 016 * 017 * @param action the action to run. 018 */ 019 public void bind(Runnable action) { 020 m_bindings.add(action); 021 } 022 023 /** Poll all bindings. */ 024 public void poll() { 025 m_bindings.forEach(Runnable::run); 026 } 027 028 /** Clear all bindings. */ 029 public void clear() { 030 m_bindings.clear(); 031 } 032}