class CompletableResultCode {

  public static CompletableResultCode ofAll(final Collection<CompletableResultCode> codes) {
    final CompletableResultCode result = new CompletableResultCode();
    final AtomicInteger pending = new AtomicInteger(codes.size());
    final AtomicBoolean failed = new AtomicBoolean();
    for (final CompletableResultCode code : codes) {
      code.whenComplete(
          new Runnable() {
            @Override
            public void run() {
              if (!code.isSuccess()) {
                failed.set(true);
              }
              if (pending.decrementAndGet() == 0) {
                if (failed.get()) {
                  result.fail();
                } else {
                  result.succeed();
                }
              }
            }
          });
    }
    return result;
  }

  public  CompletableResultCode();

}