* Add scala documentation for Source.fromFuture #24933
This commit is contained in:
parent
3e698be9ce
commit
fb9bb51dc7
2 changed files with 32 additions and 0 deletions
|
|
@ -26,3 +26,7 @@ If the future fails the stream is failed with that exception.
|
|||
|
||||
@@@
|
||||
|
||||
## Example
|
||||
Scala
|
||||
: @@snip [SourceFromFuture.scala]($akka$/akka-docs/src/test/scala/docs/stream/operators/SourceOperators.scala) { #sourceFromFuture }
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators
|
||||
|
||||
object SourceOperators {
|
||||
|
||||
def fromFuture = {
|
||||
//#sourceFromFuture
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.{ Done, NotUsed }
|
||||
import akka.stream.scaladsl._
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
implicit val system: ActorSystem = ActorSystem()
|
||||
implicit val materializer: ActorMaterializer = ActorMaterializer()
|
||||
|
||||
val source: Source[Int, NotUsed] = Source.fromFuture(Future.successful(10))
|
||||
val sink: Sink[Int, Future[Done]] = Sink.foreach((i: Int) ⇒ println(i))
|
||||
|
||||
val done: Future[Done] = source.runWith(sink) //10
|
||||
//#sourceFromFuture
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue