pekko/docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.4 KiB
Java
Raw Normal View History

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, derived from Akka.
*/
2018-05-27 21:49:12 -03:00
/*
2022-02-04 12:36:44 +01:00
* Copyright (C) 2018-2022 Lightbend Inc. <https://www.lightbend.com>
2018-05-27 21:49:12 -03:00
*/
package jdocs.stream;
import org.apache.pekko.NotUsed;
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.japi.function.Function;
import org.apache.pekko.stream.javadsl.Source;
import org.apache.pekko.stream.javadsl.Sink;
2018-05-27 21:49:12 -03:00
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;
2018-05-27 21:49:12 -03:00
@BeforeClass
public static void setup() {
system = ActorSystem.create("SinkRecipeDocTest");
}
2018-05-27 21:49:12 -03:00
@Test
public void foreachAsync() {
final Function<Integer, CompletionStage<Void>> asyncProcessing =
param -> CompletableFuture.completedFuture(param).thenAccept(System.out::println);
2018-05-27 21:49:12 -03:00
// #forseachAsync-processing
// final Function<Integer, CompletionStage<Void>> asyncProcessing = _
2018-05-27 21:49:12 -03:00
final Source<Integer, NotUsed> numberSource = Source.range(1, 100);
2018-05-27 21:49:12 -03:00
numberSource.runWith(Sink.foreachAsync(10, asyncProcessing), system);
// #forseachAsync-processing
}
2018-05-27 21:49:12 -03:00
}