private void readNextMessage() {
                        if (messageWaiting == null) { // do not run if value waiting to be put
                            try {
                              returnQueue.put(new Object()); // allow other thread to gather result
                              messageWaiting = synchronousQueue.take();

                            } catch (final InterruptedException e) {
                                messageWaiting = new EndMessage();
                            }
                        }
                    }
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