presto-main/src/main/java/io/prestosql/execution/FutureStateChange.java/FutureStateChange/createNewListener
class FutureStateChange:    public ListenableFuture<T> createNewListener()
    {
        SettableFuture<T> listener = SettableFuture.create();
        synchronized (listeners) {
            listeners.add(listener);
        }

        // remove the listener when the future completes
        listener.addListener(
                () -> {
                    synchronized (listeners) {
                        listeners.remove(listener);
                    }
                },
                directExecutor());

        return listener;
    }