def transfer_result(fut, errors_only=False, process=None):
    """
    Return a ``done_callback`` that transfers the result, errors or cancellation
    to the provided future.

    If errors_only is ``True`` then it will not transfer a successful result
    to the provided future.

    .. code-block:: python

        from photons_app import helpers as hp

        import asyncio


        async def my_coroutine():
            return 2

        fut = hp.create_future()
        task = hp.async_as_background(my_coroutine())
        task.add_done_callback(hp.transfer_result(fut))

        assert (await fut) == 2

    If process is provided, then when the coroutine is done, process will be
    called with the result of the coroutine and the future that result is being
    transferred to.
    """

    def transfer(res):
        if res.cancelled():
            fut.cancel()
            return

        exc = res.exception()

        if fut.done():
            return

        if exc is not None:
            fut.set_exception(exc)
            return

        if not errors_only:
            fut.set_result(res.result())

        if process:
            process(res, fut)

    return transfer