package common;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

public class ConsumerSignal<T> {
	private final Set<Consumer<T>> listeners;

	public ConsumerSignal() {
		this.listeners = new HashSet<>();
	}

	public void connect(Consumer<T> listener) {
		this.listeners.add(listener);
	}

	public void clear() {
		this.listeners.clear();
	}

	public void emit(T arg) {
		for (Consumer<T> listener : this.listeners) {
			listener.accept(arg);
		}
	}
}
