code: @Override
      public IPromise then(Callback resultCB) {
          // FIXME: this can be implemented more efficient
          while( !lock.compareAndSet(false,true) ) {}
          try {
              if (resultReceiver != null)
                  throw new RuntimeException("Double register of promise listener");
              resultReceiver = resultCB;
              if (hadResult) {
                  hasFired = true;
                  if (nextFuture == null) {
                      nextFuture = new Promise(result, error);
                      lock.set(false);
                      resultCB.complete(result, error);
                  } else {
                      lock.set(false);
                      resultCB.complete(result, error);
                      nextFuture.complete(result, error);
                      return nextFuture;
                  }
              }
              if (resultCB instanceof IPromise) {
                  return (IPromise) resultCB;
              }
              lock.set(false);
              while( !lock.compareAndSet(false,true) ) {}
              if (nextFuture == null) {
                  return nextFuture = new Promise();
              } else {
                  return nextFuture;
              }
          } finally {
              lock.set(false);
          }
      }
docs: see IPromise (inheriting Callback) interface