Class ClosingFuture.DeferredCloser

    • Method Detail

      • eventuallyClose

        @CanIgnoreReturnValue
        @NullableDecl
        public <C extends Object & Closeable> C eventuallyClose​(@NullableDecl
                                                                C closeable,
                                                                Executor closingExecutor)
        Captures an object to be closed when a ClosingFuture pipeline is done.

        For users of the -jre flavor of Guava, the object can be any AutoCloseable. For users of the -android flavor, the object must be a Closeable. (For more about the flavors, see Adding Guava to your build.)

        Be careful when targeting an older SDK than you are building against (most commonly when building for Android): Ensure that any object you pass implements the interface not just in your current SDK version but also at the oldest version you support. For example, API Level 16 is the first version in which Cursor is Closeable. To support older versions, pass a wrapper Closeable with a method reference like cursor::close.

        Note that this method is still binary-compatible between flavors because the erasure of its parameter type is Object, not AutoCloseable or Closeable.

        Parameters:
        closeable - the object to be closed (see notes above)
        closingExecutor - the object will be closed on this executor
        Returns:
        the first argument