You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library provides an implementation of the CompletionStage interface and related classes these are designed to support long-running blocking tasks (typically, I/O bound) - unlike Java 8 built-in implementation, [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html), that is primarily supports computational tasks.
4
4
# Why a CompletableFuture is not enough?
@@ -41,6 +41,29 @@ CompletableTask
41
41
```
42
42
All of `myValueGenerator`, `myConsumer`, `myActtion` will be executed using `myExecutor`
43
43
44
+
b. `CompletableTask.complete(T value, Executor executor)`
45
+
46
+
Same as above, but the starting point is a resolved Promise with a specified value:
47
+
```
48
+
CompletableTask
49
+
.complete("Hello!", myExecutor)
50
+
.thenApplyAsync(myMapper)
51
+
.thenApplyAsync(myTransformer)
52
+
.thenAcceptAsync(myConsumer)
53
+
.thenRunAsync(myAction);
54
+
```
55
+
All of `myMapper`, `myTransformer`, `myConsumer`, `myActtion` will be executed using `myExecutor`
56
+
57
+
Additionally, you may use submit [Supplier](https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html) / [Runnable](https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html) to the [Executor](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html) right away, in a similar way as with [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html):
Most importantly, all composed promises support true cancellation (incl. interrupting thread) for the functions supplied as arguments:
45
68
```
46
69
Promise<?> p1 =
@@ -55,19 +78,6 @@ p1.cancel(true);
55
78
```
56
79
In the example above `myConsumer` will be interrupted if already in progress. Both `p1` and `p2` will be resolved faulty: `p1` with [CancellationException](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CancellationException.html) and `p2` with [CompletionException](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionException.html).
57
80
58
-
b. `CompletableTask.complete(T value, Executor executor)`
59
-
60
-
Same as above, but the starting point is a resolved Promise with a specified value:
61
-
```
62
-
CompletableTask
63
-
.complete("Hello!", myExecutor)
64
-
.thenApplyAsync(myMapper)
65
-
.thenApplyAsync(myTransformer)
66
-
.thenAcceptAsync(myConsumer)
67
-
.thenRunAsync(myAction);
68
-
```
69
-
All of `myMapper`, `myTransformer`, `myConsumer`, `myActtion` will be executed using `myExecutor`
70
-
71
81
## 3. Helper class Promises
72
82
The class
73
83
provides convenient methods to combine several `CompletionStage`-s:
0 commit comments