https://github.com/fschopp/java-futures
Bridge gaps and help overcome inconveniences with CompletableFuture
https://github.com/fschopp/java-futures
completablefuture
Last synced: about 2 months ago
JSON representation
Bridge gaps and help overcome inconveniences with CompletableFuture
- Host: GitHub
- URL: https://github.com/fschopp/java-futures
- Owner: fschopp
- License: bsd-3-clause
- Created: 2016-02-26T21:29:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-15T00:05:48.000Z (almost 10 years ago)
- Last Synced: 2025-08-04T12:41:36.636Z (7 months ago)
- Topics: completablefuture
- Language: Java
- Homepage:
- Size: 259 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Bridge gaps and help overcome inconveniences with
[`CompletableFuture`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html).
## Status
[](https://travis-ci.org/fschopp/java-futures)
[](http://search.maven.org/#search|gav|1|g:net.florianschoppmann.java%20AND%20a:java-futures)
## Overview
- requires Java 8
- methods that collect the results of multiple completion stages into a `List`
future, both with short-circuit semantics (fail early if an input completion
stage fails) and without (guaranteed not to be completed while there are
uncompleted input stages)
- equivalent methods for
[`supplyAsync`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#supplyAsync-java.util.function.Supplier-),
[`thenApply`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#thenApply-java.util.function.Function-),
[`thenCompose`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#thenCompose-java.util.function.Function-),
etc. that accept functions throwing checked exceptions
- method similar to Scala’s
[`Promise#completeWith`](http://www.scala-lang.org/api/current/index.html#scala.concurrent.Promise@completeWith(other:scala.concurrent.Future[T]):Promise.this.type)
- method for unwrapping
[`CompletionException`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionException.html)
- method for exception mapping
- methods for dealing with asynchronous
“[try-with-resources](https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20.3)”
scenarios
- tests have virtually
[full code coverage](http://fschopp.github.io/java-futures/snapshot/jacoco)
## License
[Revised BSD (3-Clause) License](LICENSE)
## Binary Releases
Published releases (compiled for Java 8 and up) are available on Maven Central.
```
net.florianschoppmann.java
java-futures
1.1.0
```
## Documentation
For current snapshot:
- [API documentation](http://fschopp.github.io/java-futures/snapshot/apidocs)
- [Maven-generated project documentation](http://fschopp.github.io/java-futures/snapshot)
Release documentation is available by replacing “snapshot” in the URL by the
respective version number (such as “1.1.0”).
## Usage Examples
The following examples show some use cases of class `Futures` provided by this
project.
### Collect the results of multiple completion stages into a `List` future
```java
CompletableFuture sum(Set> set) {
return Futures.shortCircuitCollect(set)
.thenApply(list -> list.stream().mapToInt(Integer::intValue).sum());
}
```
### Equivalent methods allowing for checked exceptions
```java
CompletableFuture fileSize(CompletionStage filePathStage,
Executor executor) {
// Note that Files#size(Path) throws an IOException, hence it would have to
// be wrapped in the lambda expression passed to
// CompletionStage#thenApply(Function).
return Futures.thenApplyAsync(filePathStage, Files::size, executor);
}
```