All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bigcustard.util.Watchable Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.bigcustard.util;

import com.badlogic.gdx.utils.Disposable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class Watchable implements Disposable {
    private List> watchers = new ArrayList<>();

    public Watchable watch(Consumer watcher) {
        watchers.add(watcher);
        return this;
    }

    public void broadcast(T object) {
        watchers.forEach((l) -> l.accept(object));
    }

    @Override
    public void dispose() {
        watchers.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy