Sink.ignore

Consume all elements but discards them.

Sink operators

Signature

Sink.ignoreSink.ignore

Description

Consume all elements but discards them. Useful when a stream has to be consumed but there is no use to actually do anything with the elements in the Sink. Processing of the elements may occur in the Source/Flow.

Example

This examples reads lines from a file, saves them to a database, and stores the database identifiers in another file. The stream is run with Sink.ignore because all processing of the elements have been performed by the preceding stream operators.

Scala
sourceval lines: Source[String, NotUsed] = readLinesFromFile()
val databaseIds: Source[UUID, NotUsed] =
  lines.mapAsync(1)(line => saveLineToDatabase(line))
databaseIds.mapAsync(1)(uuid => writeIdToFile(uuid)).runWith(Sink.ignore)
Java
sourceSource<String, NotUsed> lines = readLinesFromFile();
Source<UUID, NotUsed> databaseIds = lines.mapAsync(1, line -> saveLineToDatabase(line));
databaseIds.mapAsync(1, uuid -> writeIdToFile(uuid)).runWith(Sink.ignore(), system);

Reactive Streams semantics

cancels never

backpressures never

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.