1. # HyperIterator is done by things that know how to get a batch of values
  2. # filled up, and maybe to process it.
  3. my class HyperWorkBuffer { ... }
  4. my class HyperConfiguration { ... }
  5. my role HyperIterator {
  6. # Called in order to fill up a work buffer with items. For things that
  7. # can be part of a pipeline of operations, this simply defers to the
  8. # next thing in the pipeline, up until a source is reached. The source
  9. # should push items to the input of the work buffer. Only one thread
  10. # can ever be calling fill-batch on a given iterator chain at a time
  11. # (usually the co-ordinating thread), so you can safely consume items
  12. # from any usual iterable to fill the batch. Return IterationEnd if this
  13. # is the last buffer you can produce, and anything else otherwise.
  14. method fill-buffer(HyperWorkBuffer:D $work, int $items) { ... }
  15. # Process the provided work buffer. If you are a source, then return Mu.
  16. # If you are a processing stage, you should pass the work buffer down to
  17. # the next process-buffer in the chain. If it returns a HyperWorkBuffer,
  18. # then .swap() it so the previous stage's output is now your input, and
  19. # then process it, putting your results into the output buffer. This is
  20. # the code that can run on any thread; keep it side-effect free.
  21. method process-buffer(HyperWorkBuffer:D $work) { ... }
  22. # Gets HyperConfiguration information for this parallelized operation.
  23. # Processing stages should ask their source.
  24. method configuration() { ... }
  25. }