Source.single
Stream a single object
Description
Stream a single object
emits the value once
completes when the single value has been emitted
Examples
- Scala
-
source
import akka.stream._ val s: Future[immutable.Seq[Int]] = Source.single(1).runWith(Sink.seq) s.foreach(list => println(s"Collected elements: $list")) // prints: Collected elements: List(1)
- Java
-
source
import akka.stream.*; CompletionStage<List<String>> future = Source.single("A").runWith(Sink.seq(), materializer); CompletableFuture<List<String>> completableFuture = future.toCompletableFuture(); completableFuture.thenAccept(result -> System.out.printf("collected elements: %s\n", result)); // result list will contain exactly one element "A"