code: def _chain_resolve(ctx, old_future, on_success=None, on_failure=None):
      new_future = ctx.pop()
      if old_future.cancelled() or new_future.cancelled():
          new_future.cancel()
          new_future.set_running_or_notify_cancel()
          return
      try:
          if old_future.exception() is not None:
              _chain_resolve_failure(
                  new_future,
                  old_future.exception(),
                  on_failure,
              )
          else:
              try:
                  _chain_resolve_success(
                      new_future,
                      old_future.result(),
                      on_success,
                  )
              except BaseException as exception:
                  _chain_resolve_failure(
                      new_future,
                      exception,
                      on_failure,
                  )
      finally:
          del new_future, old_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 8 for calling a global function with example usage: _chain_resolve(ctx, old_future, on_success, on_failure) without return types