akka/akka-core

Support non-eager cancellation for alsoTo steam combinator

オープン

#27,618 opened on 2019/09/03

 (6 件のコメント) (1 件のリアクション) (0 人の担当者)Scala (3,547 件のフォーク)batch import
1 - triagedhelp wantedt:stream

Repository metrics

Stars
 (13,277 個のスター)
PR merge metrics
 (平均マージ 8d 19h) (30d で 10 merged PRs)

説明

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?

コントリビューターガイド