code: def fail_to(future):
      
      assert is_future(future), 'you forgot to pass a future'
  
      def decorator(f):
  
          @wraps(f)
          def new_f(*args, **kwargs):
              try:
                  return f(*args, **kwargs)
              except Exception:
                  future.set_exc_info(sys.exc_info())
  
          return new_f
  
      return decorator
docs: A decorator for function callbacks to catch uncaught non-async
      exceptions and forward them to the given future.
  
      The primary use for this is to catch exceptions in async callbacks and
      propagate them to futures. For example, consider,
  
      .. code-block:: python
  
          answer = Future()
  
          def on_done(future):
              foo = bar()
              answer.set_result(foo)
  
          some_async_operation().add_done_callback(on_done)
  
      If ``bar()`` fails, ``answer`` will never get filled with an exception or
      a result. Now if we change ``on_done`` to,
  
      .. code-block:: python
  
          @fail_to(answer)
          def on_done(future):
              foo = bar()
              answer.set_result(foo)
  
      Uncaught exceptions in ``on_done`` will be caught and propagated to
      ``answer``. Note that ``on_done`` will return None if an exception was
      caught.
  
      :param answer:
          Future to which the result will be written.