completionTimeout

If the completion of the stream does not happen until the provided timeout, the stream is failed with a TimeoutException.

Time aware operators

Signature

Source.completionTimeoutSource.completionTimeout Flow.completionTimeoutFlow.completionTimeout

Description

If the completion of the stream does not happen until the provided timeout, the stream is failed with a TimeoutException.

Example

This example reads the numbers from a source and do some calculation in the flow with a completion timeout of 10 milliseconds. It will fail the stream, leading to failing the materialized Future CompletionStage if the stream has not completed mapping the numbers from the source when the timeout hits.

Scala
sourceval source = Source(1 to 10000).map(number => number * number)
source.completionTimeout(10.milliseconds).run()
Java
sourceSource<Integer, NotUsed> source = Source.range(1, 100000).map(number -> number * number);
CompletionStage<Done> result = source.completionTimeout(Duration.ofMillis(10)).run(system);
return result;

Reactive Streams semantics

emits when upstream emits an element

backpressures when downstream backpressures

completes when upstream completes or fails if timeout elapses before upstream completes

cancels when downstream cancels

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.