#18021 Sink.seq and FlowOps.limit and .limitWeighted
This commit is contained in:
parent
52655f2836
commit
aadaf15b89
13 changed files with 472 additions and 0 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue