FinallyFunction (Apache Hadoop HDFS-RBF 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.federation.router.async.utils, interface: FinallyFunction

Package org.apache.hadoop.hdfs.server.federation.router.async.utils

# Interface FinallyFunction<R>

Type Parameters:
  `R` - the type of the result of the asynchronous operation

Functional Interface:
  This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface FinallyFunction<R>
The `FinallyFunction` interface represents a function that is used to perform final actions after an asynchronous operation completes, regardless of whether the operation was successful or resulted in an exception. This interface is part of the asynchronous utilities provided by the Hadoop Distributed File System (HDFS) Federation router.

A `FinallyFunction` is typically used for cleanup or finalization tasks, such as releasing resources, closing connections, or performing other actions that need to occur after all other operations have completed.

An implementation of this interface should define what the final action is. It takes the result of the asynchronous operation as an argument and returns a new result, which can be the same as the input result or a modified version of it.

FinallyFunction is used to implement the following semantics:

        try{
          R res = doAsync(input);
        } catch(...) {
          ...
        } finally {
          // Can use FinallyFunction
          R result = thenApply(res);
        }

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default CompletableFuture<R>`
  `apply(CompletableFuture<R> in)`
  Applies this final action function to a `CompletableFuture`, which is expected to be the result of an asynchronous operation.
  `R`
  `apply(R r)`
  Applies this final action function to the result of an asynchronous operation.

- ## Method Details

  - ### apply

    R apply(R r) throws IOException
    Applies this final action function to the result of an asynchronous operation.
    Parameters:
      `r` - the result of the asynchronous operation, which may be null if the operation did not complete successfully
    Returns:
      the result after applying the final action, which may be a new result or a modified version of the input result
    Throws:
      `IOException` - if an I/O error occurs during the application of the final action

  - ### apply

    default CompletableFuture<R> apply(CompletableFuture<R> in)
    Applies this final action function to a `CompletableFuture`, which is expected to be the result of an asynchronous operation.

    This method is a convenience that simplifies the use of `FinallyFunction` with asynchronous operations. It handles the completion of the future and applies the `FinallyFunction` to the result.

    Parameters:
      `in` - the `CompletableFuture` representing the asynchronous operation
    Returns:
      a new `CompletableFuture` that completes with the result of applying the final action function