public Optional<Dir> next(final long time, final TimeUnit unit) {
        Dir dir = null;
        try {
            lock.lockInterruptibly();
            try {
                while (dir == null) {
                    while (readId > writeId) {
                        if (!condition.await(time, unit)) {
                            return Optional.empty();
                        }
                    }
                    final long id = readId++;
                    final Path path = DirUtil.createPath(rootDir, id);
                    if (Files.isDirectory(path)) {
                        dir = createDir(id, path);
                    }
                }
            } finally {
                lock.unlock();
            }
        } catch (final InterruptedException e) {
            throw UncheckedInterruptedException.create(e);
        }
        LOGGER.trace("{} ({}) - next() time: {}, unit: {}, dir: {}", name, rootDir, time, unit, dir);
        return Optional.of(dir);
    }
Get the next dir that is available in the queue as soon as one is available, block until then or timeout.

@return A dir that is managed by this queue. The dir should be closed once used to ensure parent dirs are
deleted if empty.
stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/DirQueue.java