1. # A RaceSeq performs batches of work in parallel, and will deliver the results
  2. # in the order they are produced (so potentially disordering them relative to
  3. # the input).
  4. my class RaceSeq does Iterable does Sequence {
  5. has HyperConfiguration $.configuration;
  6. has Rakudo::Internals::HyperWorkStage $!work-stage-head;
  7. submethod BUILD(:$!configuration!, :$!work-stage-head!) {}
  8. method iterator(RaceSeq:D: --> Iterator) {
  9. my $joiner := Rakudo::Internals::RaceToIterator.new:
  10. source => $!work-stage-head;
  11. Rakudo::Internals::HyperPipeline.start($joiner, $!configuration);
  12. $joiner
  13. }
  14. method grep(RaceSeq:D: $matcher, *%options) {
  15. Rakudo::Internals::HyperRaceSharedImpl.grep:
  16. self, $!work-stage-head, $matcher, %options
  17. }
  18. method hyper(RaceSeq:D:) {
  19. HyperSeq.new(:$!configuration, :$!work-stage-head)
  20. }
  21. method is-lazy() { False }
  22. method map(RaceSeq:D: $matcher, *%options) {
  23. Rakudo::Internals::HyperRaceSharedImpl.map:
  24. self, $!work-stage-head, $matcher, %options
  25. }
  26. method race(RaceSeq:D:) { self }
  27. multi method serial(RaceSeq:D:) { self.Seq }
  28. method sink(--> Nil) {
  29. Rakudo::Internals::HyperRaceSharedImpl.sink(self, $!work-stage-head)
  30. }
  31. }