Skip to content

Commit 2bf9fbd

Browse files
committed
docs: improve wording 📚
1 parent b7534e1 commit 2bf9fbd

File tree

10 files changed

+425
-231
lines changed

10 files changed

+425
-231
lines changed

README.md

Lines changed: 185 additions & 125 deletions
Large diffs are not rendered by default.

cffu-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<artifactId>cffu2</artifactId>
1212
<name>CompletableFuture-Fu(cffu)</name>
1313
<description>
14-
🦝 Java CompletableFuture-Fu ("CF-Fu", pronounced "Shifu" 🦝) is a tiny 0-dependency sidekick library
14+
🦝 Java CompletableFuture-Fu ("CF-Fu", pronounced "Shifu" 🦝) is a tiny 0-dependency library
1515
that improves the CompletableFuture(CF) usage experience and reduces misuse,
1616
enabling more convenient, efficient, and safe use of `CF` in your application. 😋🚀🦺
1717
</description>

cffu-core/src/main/java/io/foldright/cffu2/BaseCffu.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626

2727
/**
28-
* Base class providing shared functionality for {@link Cffu} and {@link MCffu} implementations.
29-
* For application, should use {@link Cffu} or {@link MCffu} directly rather than this internal class.
28+
* Base class providing shared functionality for {@link Cffu} and {@link MCffu} subclass implementations.
29+
* For application code, should always use type {@link Cffu} or {@link MCffu} rather than this type {@link BaseCffu}.
3030
*
3131
* @param <T> The result type returned by this future's {@code join}
3232
* @param <F> the type of the implementation {@code BaseCffu}

cffu-core/src/main/java/io/foldright/cffu2/CfParallelUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
/**
24-
* Utility class for parallel data processing using CompletableFuture.
24+
* Utility class for async parallel data processing using CompletableFuture.
2525
* <p>
2626
* Supports different concurrency strategies:
2727
* all-fail-fast, all-success, most-success, all-complete, any-success and any-complete.

cffu-core/src/main/java/io/foldright/cffu2/CompletableFutureUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323

2424
/**
25-
* This class contains the new enhanced and backport methods for {@link CompletableFuture}.
25+
* Utility class providing enhanced and backport methods for {@link CompletableFuture}.
2626
*
2727
* @author Jerry Lee (oldratlee at gmail dot com)
2828
* @author HuHao (995483610 at qq dot com)
2929
* @author Eric Lin (linqinghua4 at gmail dot com)
30+
* @see CompletableFuture
3031
* @see CfIterableUtils
3132
* @see CfParallelUtils
3233
* @see CfTupleUtils

cffu-core/src/main/java/io/foldright/cffu2/package-info.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/**
22
*
3-
* A tiny 0-dependency sidekick library that improves the CompletableFuture(CF) usage experience and reduces misuse,
3+
* A tiny 0-dependency library that improves the CompletableFuture(CF) usage experience and reduces misuse,
44
* enabling more convenient, efficient, and safe use of `CF` in your application. 😋🚀🦺
5-
* <p> The core classes are {@link io.foldright.cffu2.Cffu}/{@link io.foldright.cffu2.CffuFactory}. And the core
6-
* util class {@link io.foldright.cffu2.CompletableFutureUtils} of {@link java.util.concurrent.CompletableFuture}
5+
* <p>
6+
* <ul>
7+
* <li>The core classes are {@link io.foldright.cffu2.Cffu}/{@link io.foldright.cffu2.CffuFactory}.
8+
* <li>the core util class {@link io.foldright.cffu2.CompletableFutureUtils} of {@link java.util.concurrent.CompletableFuture}
79
* contains the enhanced and backport methods for {@link java.util.concurrent.CompletableFuture}.
10+
* </ul>
811
*
912
* @author Jerry Lee (oldratlee at gmail dot com)
1013
* @see io.foldright.cffu2.Cffu
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package io.foldright.demo;
2+
3+
import io.foldright.cffu2.CfParallelUtils;
4+
import io.foldright.cffu2.CffuFactory;
5+
import io.foldright.cffu2.CompletableFutureUtils;
6+
import io.foldright.cffu2.MCffu;
7+
8+
import java.util.List;
9+
import java.util.concurrent.CompletableFuture;
10+
import java.util.concurrent.ExecutorService;
11+
import java.util.concurrent.Executors;
12+
import java.util.function.Function;
13+
14+
import static io.foldright.test_utils.TestUtils.sleep;
15+
import static java.util.Arrays.asList;
16+
import static java.util.concurrent.CompletableFuture.completedFuture;
17+
18+
19+
/**
20+
* This shows the usage of Multiple Actions methods(<b>M</b> Methods).
21+
* <p>
22+
* Run by maven: {@code
23+
* mvn -pl cffu-core test-compile exec:exec -Dexec.mainClass=io.foldright.demo.MultipleActionsDemo
24+
* }
25+
*/
26+
public class CfParallelDemo {
27+
private static final ExecutorService myBizExecutor = Executors.newCachedThreadPool();
28+
private static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build();
29+
30+
public static void main(String[] args) {
31+
parApplyFailFastAsyncDemo();
32+
thenParApplyFailFastAsyncDemo();
33+
34+
////////////////////////////////////////
35+
// cleanup
36+
////////////////////////////////////////
37+
myBizExecutor.shutdown();
38+
}
39+
40+
static void parApplyFailFastAsyncDemo() {
41+
Function<Integer, Integer> fn = x -> x + 1;
42+
final List<Integer> list = asList(42, 43, 44);
43+
44+
// wrap data with action to CompletableFutures first, AWKWARD and COMPLEX! 😖
45+
@SuppressWarnings("unchecked")
46+
CompletableFuture<Integer>[] cfs = new CompletableFuture[list.size()];
47+
for (int i = 0; i < list.size(); i++) {
48+
Integer e = list.get(i);
49+
cfs[i] = CompletableFuture.supplyAsync(() -> fn.apply(e));
50+
}
51+
CompletableFutureUtils.allResultsFailFastOf(cfs).thenAccept(System.out::println);
52+
// output: [43, 44, 45]
53+
cffuFactory.allResultsFailFastOf(cfs).thenAccept(System.out::println);
54+
// output: [43, 44, 45]
55+
56+
// just process multiple data, fresh and cool 😋
57+
CfParallelUtils.parApplyFailFastAsync(
58+
asList(42, 43, 44),
59+
x -> x + 1
60+
).thenAccept(System.out::println);
61+
// output: [43, 44, 45]
62+
cffuFactory.parOps().parApplyFailFastAsync(
63+
asList(42, 43, 44),
64+
x -> x + 1
65+
).thenAccept(System.out::println);
66+
// output: [43, 44, 45]
67+
68+
sleep(1000);
69+
}
70+
71+
static void thenParApplyFailFastAsyncDemo() {
72+
Function<Integer, Integer> fn = x -> x + 1;
73+
final CompletableFuture<List<Integer>> cf = completedFuture(asList(42, 43, 44));
74+
75+
// wrap data with action to CompletableFutures first, AWKWARD and COMPLEX! 😖
76+
cf.thenCompose(list -> {
77+
@SuppressWarnings("unchecked")
78+
CompletableFuture<Integer>[] cfs = new CompletableFuture[list.size()];
79+
for (int i = 0; i < list.size(); i++) {
80+
Integer e = list.get(i);
81+
cfs[i] = CompletableFuture.supplyAsync(() -> fn.apply(e));
82+
}
83+
return CompletableFutureUtils.allResultsFailFastOf(cfs);
84+
}).thenAccept(System.out::println);
85+
// output: [43, 44, 45]
86+
final MCffu<Integer, List<Integer>> mCffu = cffuFactory.completedMCffu(asList(42, 43, 44));
87+
mCffu.thenCompose(list -> {
88+
@SuppressWarnings("unchecked")
89+
CompletableFuture<Integer>[] cfs = new CompletableFuture[list.size()];
90+
for (int i = 0; i < list.size(); i++) {
91+
Integer e = list.get(i);
92+
cfs[i] = CompletableFuture.supplyAsync(() -> fn.apply(e));
93+
}
94+
return CompletableFutureUtils.allResultsFailFastOf(cfs);
95+
}).thenAccept(System.out::println);
96+
// output: [43, 44, 45]
97+
98+
// just process multiple data, fresh and cool 😋
99+
CfParallelUtils.thenParApplyFailFastAsync(cf, x -> x + 1)
100+
.thenAccept(System.out::println);
101+
// output: [43, 44, 45]
102+
mCffu.parOps().thenParApplyFailFastAsync(x -> x + 1)
103+
.thenAccept(System.out::println);
104+
// output: [43, 44, 45]
105+
106+
sleep(1000);
107+
}
108+
}

cffu-core/src/test/java/io/foldright/demo/MultipleActionsDemo.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.foldright.demo;
22

3-
import io.foldright.cffu2.CfTupleUtils;
43
import io.foldright.cffu2.CffuFactory;
54
import io.foldright.cffu2.CompletableFutureUtils;
65

@@ -99,20 +98,6 @@ static void thenMApplyAsyncDemo() {
9998
).thenAccept(System.out::println);
10099
// output: [43, 44, 45]
101100

102-
CfTupleUtils.thenMApplyTupleFailFastAsync(
103-
completedFuture(42),
104-
v -> "string" + v,
105-
v -> v + 1,
106-
v -> v + 2.1
107-
).thenAccept(System.out::println);
108-
// output: Tuple3(string42, 43, 44.1)
109-
cffuFactory.completedFuture(42).tupleOps().thenMApplyAllSuccessTupleAsync(
110-
v -> "string" + v,
111-
v -> v + 1,
112-
v -> v + 2.1
113-
).thenAccept(System.out::println);
114-
// output: Tuple3(string42, 43, 44.1)
115-
116101
sleep(1000);
117102
}
118103
}

0 commit comments

Comments
 (0)