Skip to content

Commit c06d70a

Browse files
committed
Add notes about methods returning Future-like objects to Ft.2 and Ft.3
1 parent 9333ebc commit c06d70a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,13 @@ has [multiple failure paths](#future-method-failure-paths): either the future ma
13661366
exceptionally, or the method itself may throw an exception (typically from the blocking operation),
13671367
which is illustrated by `getSalary() throws ConnectionException` in the above examples.
13681368

1369+
This advice also applies when a method returns any object representing an asynchronous execution
1370+
other than `Future`, such as [`Flow.Publisher`](
1371+
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/Flow.Publisher.html
1372+
), [`org.reactivestreams.Publisher`](
1373+
https://www.reactive-streams.org/reactive-streams-1.0.3-javadoc/org/reactivestreams/Publisher.html),
1374+
or RxJava's [`Observable`](http://reactivex.io/RxJava/javadoc/io/reactivex/Observable.html).
1375+
13691376
<a name="future-method-failure-paths"></a>
13701377
[#](#future-method-failure-paths) Ft.3. If a method returns a `Future` and some logic in the
13711378
beginning of it may lead to an *expected failure* (i. e. not a result of a programming bug), **was
@@ -1399,6 +1406,10 @@ Future<Response> makeQuery(String query) {
13991406
The point of this refactoring is unification of failure paths, so that the users of the API don't
14001407
have to deal with multiple different ways of handling errors from the method.
14011408

1409+
Similarly to [the previous item](#future-method-no-blocking), this consideration also applies when
1410+
a method returns any object representing an asynchronous execution other than `Future`, such as a
1411+
`Publisher`.
1412+
14021413
### Thread interruption and `Future` cancellation
14031414

14041415
<a name="restore-interruption"></a>

0 commit comments

Comments
 (0)