pretty cool
This commit is contained in:
27
app/src/main/java/common/Signal1.java
Normal file
27
app/src/main/java/common/Signal1.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Signal1<T> {
|
||||
private final List<Consumer<T>> handlers;
|
||||
|
||||
public Signal1() {
|
||||
this.handlers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void connect(Consumer<T> handler) {
|
||||
this.handlers.add(handler);
|
||||
}
|
||||
|
||||
public void disconnect(Consumer<T> handler) {
|
||||
this.handlers.remove(handler);
|
||||
}
|
||||
|
||||
public void emit(T arg) {
|
||||
for (Consumer<T> handler : this.handlers) {
|
||||
handler.accept(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user