Add code sample for operator Source.single (#25375)
* Add code example for Source.single
This commit is contained in:
parent
61790d763d
commit
3e698be9ce
3 changed files with 43 additions and 1 deletions
|
|
@ -12,7 +12,10 @@ import akka.actor.Status;
|
|||
import akka.japi.Pair;
|
||||
import akka.japi.function.*;
|
||||
import akka.japi.pf.PFBuilder;
|
||||
//#imports
|
||||
import akka.stream.*;
|
||||
|
||||
//#imports
|
||||
import akka.stream.scaladsl.FlowSpec;
|
||||
import akka.util.ConstantFun;
|
||||
import akka.stream.stage.*;
|
||||
|
|
@ -328,6 +331,22 @@ public class SourceTest extends StreamTest {
|
|||
assertEquals("A", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustBeAbleToUseSingle() throws Exception {
|
||||
//#source-single
|
||||
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"
|
||||
|
||||
//#source-single
|
||||
// DO NOT use get() directly in your production code!
|
||||
List<String> result = completableFuture.get();
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("A", result.get(0));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustBeAbleToUsePrefixAndTail() throws Exception {
|
||||
final TestKit probe = new TestKit(system);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue