Source.single

Stream a single object once.

Source operators

Signature

Source.singleSource.single

Description

Stream a single object once and complete after thereafter.

See also:

  • repeat Stream a single object repeatedly.
  • tick A periodical repetition of an arbitrary object.
  • cycle Stream iterator in cycled manner.

Examples

Scala
sourceimport 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
sourceimport akka.stream.*;
CompletionStage<List<String>> future = Source.single("A").runWith(Sink.seq(), system);
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"

Reactive Streams semantics

emits the value once

completes when the single value has been emitted

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.