Limit and LimitWeighted operator docs #25468
This commit is contained in:
parent
ed1f107ab1
commit
589c6511bd
7 changed files with 142 additions and 17 deletions
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.sourceorflow
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.stream.scaladsl.Sink
|
||||
import akka.stream.scaladsl.Source
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
object Limit {
|
||||
|
||||
implicit val system: ActorSystem[_] = ???
|
||||
|
||||
def simple(): Unit = {
|
||||
// #simple
|
||||
val untrustedSource: Source[String, NotUsed] = Source.repeat("element")
|
||||
|
||||
val elements: Future[Seq[String]] =
|
||||
untrustedSource.limit(10000).runWith(Sink.seq)
|
||||
// #simple
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.sourceorflow
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.stream.scaladsl.Source
|
||||
import akka.util.ByteString
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
object LimitWeighted {
|
||||
|
||||
implicit val system: ActorSystem[_] = ???
|
||||
|
||||
def simple(): Unit = {
|
||||
// #simple
|
||||
val untrustedSource: Source[ByteString, NotUsed] = Source.repeat(ByteString("element"))
|
||||
|
||||
val allBytes: Future[ByteString] =
|
||||
untrustedSource.limitWeighted(max = 10000)(_.length).runReduce(_ ++ _)
|
||||
// #simple
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue