Skip to content

Commit 160bd8a

Browse files
authored
Update README.md
1 parent a083e03 commit 160bd8a

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Maven Central](https://img.shields.io/maven-central/v/net.tascalate.concurrent/net.tascalate.concurrent.lib.svg)](https://search.maven.org/#artifactdetails%7Cnet.tascalate.concurrent%7Cnet.tascalate.concurrent.lib%7C0.5.1%7Cpom) [![GitHub release](https://img.shields.io/github/release/vsilaev/tascalate-concurrent.svg)](https://github.com/vsilaev/tascalate-concurrent/releases/tag/0.5.1) [![license](https://img.shields.io/github/license/vsilaev/tascalate-concurrent.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)
1+
[![Maven Central](https://img.shields.io/maven-central/v/net.tascalate.concurrent/net.tascalate.concurrent.lib.svg)](https://search.maven.org/#artifactdetails%7Cnet.tascalate.concurrent%7Cnet.tascalate.concurrent.lib%7C0.5.2%7Cpom) [![GitHub release](https://img.shields.io/github/release/vsilaev/tascalate-concurrent.svg)](https://github.com/vsilaev/tascalate-concurrent/releases/tag/0.5.2) [![license](https://img.shields.io/github/license/vsilaev/tascalate-concurrent.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)
22
# tascalate-concurrent
33
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.
44
# Why a CompletableFuture is not enough?
@@ -41,6 +41,29 @@ CompletableTask
4141
```
4242
All of `myValueGenerator`, `myConsumer`, `myActtion` will be executed using `myExecutor`
4343

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):
58+
59+
```
60+
Promise<SomeValue> p1 = CompletableTask.supplyAsync(() -> {
61+
return blockingCalculationOfSomeValue();
62+
}, myExecutor);
63+
64+
Promise<Void> p2 = CompletableTask.supplyAsync(this::someIoBoundMethod, myExecutor);
65+
```
66+
4467
Most importantly, all composed promises support true cancellation (incl. interrupting thread) for the functions supplied as arguments:
4568
```
4669
Promise<?> p1 =
@@ -55,19 +78,6 @@ p1.cancel(true);
5578
```
5679
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).
5780

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-
7181
## 3. Helper class Promises
7282
The class
7383
provides convenient methods to combine several `CompletionStage`-s:

0 commit comments

Comments
 (0)