-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sink.asPublisher example and update doc (#30105)
Co-authored-by: Renato Cavalcanti <renato@cavalcanti.be>
- Loading branch information
1 parent
240378f
commit dd8b514
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
akka-docs/src/test/scala/docs/stream/operators/sink/AsPublisher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2020-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package docs.stream.operators.sink | ||
|
||
import scala.concurrent.{ ExecutionContextExecutor, Future } | ||
import akka.actor.ActorSystem | ||
import akka.stream.scaladsl.{ Sink, Source } | ||
|
||
object AsPublisher { | ||
implicit val system: ActorSystem = ??? | ||
implicit val ec: ExecutionContextExecutor = system.dispatcher | ||
def asPublisherExample() = { | ||
def asPublisherExample() = { | ||
//#asPublisher | ||
val source = Source(1 to 5) | ||
|
||
val publisher = source.runWith(Sink.asPublisher(false)) | ||
Source.fromPublisher(publisher).runWith(Sink.foreach(println)) // 1 2 3 4 5 | ||
Source | ||
.fromPublisher(publisher) | ||
.runWith(Sink.foreach(println)) //No output, because the source was not able to subscribe to the publisher. | ||
//#asPublisher | ||
} | ||
} | ||
} |