akka/akka-core

Support non-eager cancellation for alsoTo steam combinator

Aperta

#27.618 aperta il 3 set 2019

 (6 commenti) (1 reazione) (0 assegnatari)Scala (3547 fork)batch import
1 - triagedhelp wantedt:stream

Metriche repository

Star
 (13.277 stelle)
Metriche merge PR
 (Merge medio 8g 19h) (10 PR mergiate in 30 g)

Descrizione

Consider the following code

  val (f1, f2) = Source(1 to 100)
    .alsoToMat(Sink.head)(Keep.right)
    .toMat(Sink.last)(Keep.both)
    .run()

  for {
    head <- f1
    last <- f2
  } {
    println(s"head: $head , last: $last")
  }

This prints

head: 1 , last: 1

It appears that the behaviour of alsoTo and alsoToMat was changed as part of #24423 (a followup of #24291 ). For these cases this seams reasonable. However I commonly use alsoToMat to process one source with multiple sinks. I just found out that a sink such as Sink.head which cancels early can have unexpected effects on the other sinks.

This comment suggests adding an overload. However appearently using wireTap was suggested as an alternative. Unfortunately, wiretap will drop elements on backpressure which is not what I want in my usecase. Would it make sense to add an overloaded version of alsoTo and alsoToMat which includes an eagerCancel boolean?

Guida contributor