Limit and LimitWeighted operator docs #25468

This commit is contained in:
Johan Andrén 2020-01-08 16:26:51 +01:00 committed by GitHub
parent ed1f107ab1
commit 589c6511bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 17 deletions

View file

@ -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
}
}

View file

@ -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
}
}