public final class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static <C extends Closeable,T> |
tryWith(io.reactivex.Single<C> closeable,
io.reactivex.functions.Function<? super C,io.reactivex.Flowable<T>> mapper)
Constructs a
Flowable based upon a given Closeable and a Function mapper. |
static <C extends Closeable,T> |
tryWithSingle(io.reactivex.Single<C> closeable,
io.reactivex.functions.Function<? super C,io.reactivex.Single<T>> mapper)
Constructs a
Single based upon a given Closeable and a Function mapper. |
public static <C extends Closeable,T> io.reactivex.Flowable<T> tryWith(io.reactivex.Single<C> closeable, io.reactivex.functions.Function<? super C,io.reactivex.Flowable<T>> mapper)
Flowable
based upon a given Closeable
and a Function
mapper.
The given Closeable
is automatically closed wheneveronComplete
or onError
or Subscription.cancel()
is invoked.
This method is similar to the try-with-resources of Java 7 that closes resources at the end of the statement.
Below an example of usage: when the subscription is complete, canceled or terminates with an error, the
socket
is automatically closed.
Single<LdapClientSocket> ldapSocket = ...
tryWith(ldapSocket, socket -> socket.search(request)).subscribe(this::handleResponse, this::handleException)
C
- Any element type that extends Closeable
T
- The element type of the generated Flowablecloseable
- The Single
that encapsulates the Closeable
mapper
- A factory function to create a Flowable based upon the given Closeable
Closeable
Flowable
,
Closeable
public static <C extends Closeable,T> io.reactivex.Single<T> tryWithSingle(io.reactivex.Single<C> closeable, io.reactivex.functions.Function<? super C,io.reactivex.Single<T>> mapper)
Single
based upon a given Closeable
and a Function
mapper.
The given Closeable
is automatically closed whenever onComplete
or onError
or Subscription.cancel()
is invoked.
This method is similar to the try-with-resources of Java 7 that closes resources at the end of the statement.
Below an example of usage: when the subscription is complete, canceled or terminates with an error, the
socket
is automatically closed.
Single<LdapClientSocket> ldapSocket = ...
tryWithSingle(ldapSocket, socket -> socket.searchSingleEntry(request))
.subscribe(this::handleResponse, this::handleException)
C
- Any element type that extends Closeable
T
- The element type of the generated Singlecloseable
- The Single
that encapsulates the Closeable
mapper
- A factory function to create a Single based upon the given Closeable
Closeable
Single
,
Closeable
Copyright © 2010-2018, ForgeRock All Rights Reserved.