class IteratingCallback implements Consumer<Result<Void>> {

    public void iterate() {
        boolean process = false;

        loop:
        while (true) {
            try (Locker.Lock lock = locker.lock()) {
                switch (state) {
                    case PENDING:
                    case CALLED:
                        // process will be called when callback is handled
                        break loop;

                    case IDLE:
                        state = State.PROCESSING;
                        process = true;
                        break loop;

                    case PROCESSING:
                        iterate = true;
                        break loop;

                    case FAILED:
                    case SUCCEEDED:
                        break loop;

                    case CLOSED:
                    default:
                        throw new IllegalStateException(toString());
                }
            }
        }
        if (process)
            processing();
    }

    protected  IteratingCallback();
    protected  IteratingCallback(boolean needReset);

}