akka/akka-core

concatSubstreams hangs when used as documented.

Open

#25,814 opened on Oct 19, 2018

View on GitHub
 (14 comments) (0 reactions) (0 assignees)Scala (3,547 forks)batch import
1 - triagedhackathonhelp wantedt:docst:stream

Repository metrics

Stars
 (13,277 stars)
PR merge metrics
 (Avg merge 8d 19h) (10 merged PRs in 30d)

Description

I'm trying to use concatSubstreams to collapse the results of a groupBy in order (as I can do with rxjava/reactor etc). But when I try this with akka, it hangs after outputting the first element. The docs do indicate it could hang if the number of groupBy streams were insufficient, but the docs also include an example, which I expected to work.

The docs reference this code in the test suite.. https://github.com/akka/akka/blob/v2.5.17/akka-docs/src/test/java/jdocs/stream/SubstreamDocTest.java#L67-L70

Here's that example from the docs/test case slightly modified to run standalone (added println sink)

final ActorSystem system = ActorSystem.create("QuickStart");
final Materializer mat = ActorMaterializer.create(system);
Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
  .groupBy(3, elem -> elem % 3)
  .concatSubstreams()
  .runWith(Sink.foreach(a -> System.out.println(a)), mat);

When this runs I would expect to see

1
4
7
10
2
5
8
3
6
9

But instead I just see 1 then it hangs.

Are the docs incorrect? are groupBy/concatSubstreams defective? or am I missing something obvious as to why it isn't running?

Contributor guide