Align lazy and future operators #26446
This commit is contained in:
parent
4a72985e48
commit
74adecb4e7
59 changed files with 2091 additions and 384 deletions
|
|
@ -20,7 +20,7 @@ object SourceOperators {
|
|||
|
||||
import scala.concurrent.Future
|
||||
|
||||
val source: Source[Int, NotUsed] = Source.fromFuture(Future.successful(10))
|
||||
val source: Source[Int, NotUsed] = Source.future(Future.successful(10))
|
||||
val sink: Sink[Int, Future[Done]] = Sink.foreach((i: Int) => println(i))
|
||||
|
||||
val done: Future[Done] = source.runWith(sink) //10
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.flow
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.actor.ActorSystem
|
||||
import akka.stream.scaladsl.Flow
|
||||
import akka.stream.scaladsl.Source
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
class FutureFlow {
|
||||
|
||||
implicit val system: ActorSystem = ???
|
||||
import system.dispatcher
|
||||
|
||||
def compileOnlyBaseOnFirst(): Unit = {
|
||||
// #base-on-first-element
|
||||
def processingFlow(id: Int): Future[Flow[Int, String, NotUsed]] =
|
||||
Future {
|
||||
Flow[Int].map(n => s"id: $id, value: $n")
|
||||
}
|
||||
|
||||
val source: Source[String, NotUsed] =
|
||||
Source(1 to 10).prefixAndTail(1).flatMapConcat {
|
||||
case (List(id), tail) =>
|
||||
// base the Future flow creation on the first element
|
||||
tail.via(Flow.futureFlow(processingFlow(id)))
|
||||
}
|
||||
// #base-on-first-element
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue