code: def compose(future, resulthook=None, excepthook=None):
      """Compose the completion of a future with result and exception handlers.
  
      Args:
          future: Input future instance.
          resulthook: Function to be called once the input future completes with
              success. Once the input future finish running with success, its
              result value is the input argument for *resulthook*. The result of
              *resulthook* is set as the result of the output future.
              If *resulthook* is ``None``, the output future is completed
              directly with the result of the input future.
          excepthook: Function to be called once the input future completes with
              failure. Once the input future finish running with failure, its
              exception value is the input argument for *excepthook*.  If
              *excepthook* returns an `python:Exception` instance, it is set as
              the exception of the output future.  Otherwise, the result of
              *excepthook* is set as the result of the output future.  If
              *excepthook* is ``None``, the output future is set as failed with
              the exception from the input future.
  
      Returns:
          Output future instance to be completed once the input future is
          completed and either *resulthook* or *excepthook* finish executing.
  
      """
      new_future = future.__class__()
      new_done_cb = _functools.partial(_compose_cancel, [future])
      new_future.add_done_callback(new_done_cb)
      context = [(new_future, resulthook, excepthook)]
      done_cb = _functools.partial(_compose_complete, context)
      future.add_done_callback(done_cb)
      return new_future
  
file_path: mpi4py/src/mpi4py/futures/util.py
imports: import collections
  import functools
  import threading
  from .None import _base
label_desc: Use image node_id 2 for calling a global function with example usage: compose(future, resulthook, excepthook) and returns: new_future