Package io.servicetalk.concurrent.api
Class AsyncCloseables
- java.lang.Object
-
- io.servicetalk.concurrent.api.AsyncCloseables
-
public final class AsyncCloseables extends java.lang.Object
A utility class to createAsyncCloseable
s.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AsyncCloseables.CloseableResource
A resource that can be converted to anAsyncCloseable
.
-
Method Summary
-
-
-
Method Detail
-
closeAsyncGracefully
public static Completable closeAsyncGracefully(AsyncCloseable closable, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
InvokesAsyncCloseable.closeAsyncGracefully()
on theclosable
, applies a timeout, and if the timeout fires forces a call toAsyncCloseable.closeAsync()
.- Parameters:
closable
- TheAsyncCloseable
to initiateAsyncCloseable.closeAsyncGracefully()
on.timeout
- The timeout duration to wait forAsyncCloseable.closeAsyncGracefully()
to complete.timeoutUnit
- The time unit applied totimeout
.- Returns:
- A
Completable
that is notified once the close is complete.
-
emptyAsyncCloseable
public static ListenableAsyncCloseable emptyAsyncCloseable()
Creates an emptyListenableAsyncCloseable
that does nothing whenAsyncCloseable.closeAsync()
apart from completing theListenableAsyncCloseable.onClose()
.- Returns:
- A new
ListenableAsyncCloseable
.
-
toListenableAsyncCloseable
public static ListenableAsyncCloseable toListenableAsyncCloseable(AsyncCloseable asyncCloseable)
Wraps the passedAsyncCloseable
and creates a newListenableAsyncCloseable
. This method owns the passedAsyncCloseable
after this method returns and hence it should not be used by the caller after this method returns.- Parameters:
asyncCloseable
-AsyncCloseable
to convert toListenableAsyncCloseable
.- Returns:
- A new
ListenableAsyncCloseable
.
-
toListenableAsyncCloseable
public static ListenableAsyncCloseable toListenableAsyncCloseable(AsyncCloseable asyncCloseable, java.util.function.Function<Completable,Completable> onCloseDecorator)
Wraps the passedAsyncCloseable
and creates a newListenableAsyncCloseable
. This method owns the passedAsyncCloseable
after this method returns and hence it should not be used by the caller after this method returns.- Parameters:
asyncCloseable
-AsyncCloseable
to convert toListenableAsyncCloseable
.onCloseDecorator
-Function
that can decorate theCompletable
returned from the returnedListenableAsyncCloseable.onClose()
.- Returns:
- A new
ListenableAsyncCloseable
.
-
toAsyncCloseable
public static ListenableAsyncCloseable toAsyncCloseable(AsyncCloseables.CloseableResource closeableResource)
Creates a newListenableAsyncCloseable
which uses the passedSupplier
to get the implementation of close.- Parameters:
closeableResource
-AsyncCloseables.CloseableResource
that is to be wrapped into aListenableAsyncCloseable
.AsyncCloseables.CloseableResource.doClose(boolean)
will be called when the returnedListenableAsyncCloseable
isclosed
orgracefully closed
for the first time.- Returns:
- A new
ListenableAsyncCloseable
.
-
newCompositeCloseable
public static CompositeCloseable newCompositeCloseable()
Creates a newCompositeCloseable
.- Returns:
- A new
CompositeCloseable
.
-
-