#18021 Sink.seq and FlowOps.limit and .limitWeighted

This commit is contained in:
lolski 2015-11-19 00:11:07 +08:00 committed by Roland Kuhn
parent 52655f2836
commit aadaf15b89
13 changed files with 472 additions and 0 deletions

View file

@ -315,6 +315,20 @@ private[akka] final case class Grouped[T](n: Int) extends PushPullStage[T, immut
else ctx.absorbTermination()
}
/**
* INTERNAL API
*/
private[akka] final case class LimitWeighted[T](n: Long, costFn: T Long) extends PushStage[T, T] {
private var left = n
override def onPush(elem: T, ctx: Context[T]): SyncDirective = {
left -= costFn(elem)
if (left >= 0) ctx.push(elem)
else ctx.fail(new StreamLimitReachedException(n))
}
}
/**
* INTERNAL API
*/