public T next() {
                        readNextMessage();

                        if (StopMessage.class.isAssignableFrom(messageWaiting.getClass())) {
                            // instanceof cannot be used because of generics restriction
                            throw new NoSuchElementException();
                        }

                        final T value = currentValue = ((ValueMessage) messageWaiting).value;
                        messageWaiting = null; // for next time
                        return value;
                    }
Convert a method that implements the Collector<> class with a standard Iterable<>. This means
that the collecting method can use complex recursive logic, but still allows the calling code
to handle the results with a standard iterator. Results are returned immediately and do not
incur overhead of being stored in a list. Calculation overhead is only performed for the
results that are requested through the iterator.

This is implemented using a new thread created for the collection process, and a
SynchronousQueue<> object.
jphp-runtime/src/php/runtime/util/generator/ThreadedYieldAdapter.java