Add method foreachAsync to Sink object
This commit is contained in:
parent
ed951ccede
commit
a679f6f59e
7 changed files with 374 additions and 0 deletions
44
akka-docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java
Normal file
44
akka-docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package jdocs.stream;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.function.Function;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
import akka.stream.javadsl.Source;
|
||||
import akka.stream.javadsl.Sink;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
public class SinkRecipeDocTest extends AbstractJavaTest {
|
||||
static ActorSystem system;
|
||||
static Materializer mat;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("SinkRecipeDocTest");
|
||||
mat = ActorMaterializer.create(system);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void foreachAsync() {
|
||||
final Function<Integer, CompletionStage<Void>> asyncProcessing = param -> CompletableFuture.completedFuture(param).thenAccept(System.out::println);
|
||||
|
||||
//#forseachAsync-processing
|
||||
//final Function<Integer, CompletionStage<Void>> asyncProcessing = _
|
||||
|
||||
final Source<Integer, NotUsed> numberSource = Source.range(1, 100);
|
||||
|
||||
numberSource
|
||||
.runWith(Sink.foreachAsync(10, asyncProcessing), mat);
|
||||
//#forseachAsync-processing
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue