I try to understand the method FlowOps.delay
by experimenting with the code for two days, and there are some points that I obviously missed.
So, consider the following code:
val source = Source(1 to 100)
val flow = Flow[Int].delay(4 second, DelayOverflowStrategy.dropHead)
val sink = Sink.foreach(println)
source
.via(flow)
.to(sink)
.run
I expected him to wait 4 seconds and then print las 16 numbers from the sequence (1 to 100)
. And he behaved accordingly and after 4 seconds he put off printed numbers from 85 to 100.
Now, if I change the overflow strategy to dropTail
, it also behaves correctly and prints numbers from 1, ..., 15, 100.
That everything is fine.
Now comes the overflow strategy dropNew
and the next one
val source = Source(1 to 100)
val flow = Flow[Int].delay(4 second, DelayOverflowStrategy.dropNew)
val sink = Sink.foreach(println)
source
.via(flow)
.to(sink)
.run
, . 4 , 1,2. 4 3,4. 4 5,6. .
QUESTION1: dropNew
? 4 , 1 16, .
QUESTION2: backpressure
, , dropNew
. ? , 16 ( 16 - ), . , , 1, , , . , 4 .