Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all articles
Browse latest Browse all 1362

How splitWhen works?

$
0
0

Hello everybody!
I’m playing with akka streams and got something I don’t understands. I have simple code:
Source(1 to 100)
.throttle(1, 100.millis)
.map(x => {println("raw "+x);x})
.groupBy(10, _ % 2, false)
.concatSubstreams
.map(x => {println("concat "+x);x})
.to(Sink.ignore).run()

When I run it I get:
raw 1
concat 1
raw 2

And after this, the app is stuck, which makes perfect sense. ‘concatSubstreams’ tries to read everything from first substream, this substream is never ending, so second substream is backpressed.
But if I add ‘splitWhen’ right after groupBy it starts working!
Source(1 to 100)
.throttle(1, 100.millis)
.map(x => {println("raw "+x);x})
.groupBy(10, _ % 2, false)
.splitWhen(_ => false)
.concatSubstreams
.map(x => {println("concat "+x);x})
.to(Sink.ignore).run()

raw 1
concat 1
raw 2
concat 2
raw 3
concat 3
raw 4
concat 4
raw 5

‘splitWhen’ actually doesn’t split anything, the function I pass always return false. So, there should be the same never ending stream. Why it works now? What do i miss?

Thank you,
Andrey

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1362

Trending Articles