Doc example for Sink.head (#28782)
This commit is contained in:
parent
2cccfa3c29
commit
1545f3fb25
3 changed files with 28 additions and 0 deletions
|
|
@ -17,6 +17,14 @@ Materializes into a @scala[`Future`] @java[`CompletionStage`] which completes wi
|
|||
Materializes into a @scala[`Future`] @java[`CompletionStage`] which completes with the first value arriving,
|
||||
after this the stream is canceled. If no element is emitted, the @scala[`Future`] @java[`CompletionStage`] is failed.
|
||||
|
||||
## Example
|
||||
|
||||
Scala
|
||||
: @@snip [HeadSinkSpec.scala](/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HeadSinkSpec.scala) { #head-operator-example }
|
||||
|
||||
Java
|
||||
: @@snip [SinkDocExamples.java](/akka-docs/src/test/java/jdocs/stream/operators/SinkDocExamples.java) { #head-operator-example }
|
||||
|
||||
## Reactive Streams semantics
|
||||
|
||||
@@@div { .callout }
|
||||
|
|
|
|||
|
|
@ -78,6 +78,15 @@ public class SinkDocExamples {
|
|||
// #takeLast-operator-example
|
||||
}
|
||||
|
||||
static void headExample() {
|
||||
// #head-operator-example
|
||||
Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
CompletionStage<Integer> result = source.runWith(Sink.head(), system);
|
||||
result.thenAccept(System.out::println);
|
||||
// 1
|
||||
// #head-operator-example
|
||||
}
|
||||
|
||||
static void lastExample() {
|
||||
// #last-operator-example
|
||||
Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue