code: def _chain(future, on_success=None, on_failure=None):
      new_future = future.__class__()
      done_cb = functools.partial(
          _chain_resolve,
          [new_future],
          on_success=on_success,
          on_failure=on_failure,
      )
      future.add_done_callback(done_cb)
      return new_future
  
file_path: mpi4py/src/mpi4py/futures/aplus.py
imports: import functools
  import threading
  import weakref
  from ._base import Future
label_desc: Use image node_id 3 for calling a global function with example usage: _chain(future, on_success, on_failure) and returns: new_future