code: public IoFuture addListener(IoFutureListener<?> listener) {
          if (listener == null) {
              throw new NullPointerException("listener");
          }
  
          boolean notifyNow = false;
          synchronized (lock) {
              if (ready) {
                  notifyNow = true;
              } else {
                  if (firstListener == null) {
                      firstListener = listener;
                  } else {
                      if (otherListeners == null) {
                          otherListeners = new ArrayList<>(1);
                      }
                      otherListeners.add(listener);
                  }
              }
          }
  
          if (notifyNow) {
              notifyListener(listener);
          }
          return this;
      }
docs: {@inheritDoc}