akka/akka-core

Support non-eager cancellation for alsoTo steam combinator

Aberta

#27.618 aberto em 3 de set. de 2019

 (6 comentários) (1 reação) (0 responsável)Scala (3.547 forks)batch import
1 - triagedhelp wantedt:stream

Métricas do repositório

Stars
 (13.277 estrelas)
Métricas de merge de PR
 (Mesclagem média 8d 19h) (10 fundiu PRs em 30d)

Description

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?

Guia do colaborador