(source, destination)
Chain two futures so that when one completes, so does the other.

    The result (or exception) of source will be copied to destination.
    If destination is cancelled, source gets cancelled too.
    Compatible with both asyncio.Future and concurrent.futures.Future.
Chain two futures so that when one completes, so does the other.
Chain two futures so that when one completes so does the other .
def _chain_future(source, destination):
    """Chain two futures so that when one completes, so does the other.

    The result (or exception) of source will be copied to destination.
    If destination is cancelled, source gets cancelled too.
    Compatible with both asyncio.Future and concurrent.futures.Future.
    """
    if not isfuture(source) and not isinstance(source,
                                               concurrent.futures.Future):
        raise TypeError('A future is required for source argument')
    if not isfuture(destination) and not isinstance(destination,
                                                    concurrent.futures.Future):
        raise TypeError('A future is required for destination argument')
    source_loop = _get_loop(source) if isfuture(source) else None
    dest_loop = _get_loop(destination) if isfuture(destination) else None

    def _set_state(future, other):
        if isfuture(future):
            _copy_future_state(other, future)
        else:
            _set_concurrent_future_state(future, other)

    def _call_check_cancel(destination):
        if destination.cancelled():
            if source_loop is None or source_loop is dest_loop:
                source.cancel()
            else:
                source_loop.call_soon_threadsafe(source.cancel)

    def _call_set_state(source):
        if (destination.cancelled() and
                dest_loop is not None and dest_loop.is_closed()):
            return
        if dest_loop is None or dest_loop is source_loop:
            _set_state(destination, source)
        else:
            dest_loop.call_soon_threadsafe(_set_state, destination, source)

    destination.add_done_callback(_call_check_cancel)
    source.add_done_callback(_call_set_state)
def _chain_future ( source , destination ) : if not isfuture ( source ) and not isinstance ( source , concurrent . futures . Future ) : raise TypeError ( 'A future is required for source argument' ) if not isfuture ( destination ) and not isinstance ( destination , concurrent . futures . Future ) : raise TypeError ( 'A future is required for destination argument' ) source_loop = _get_loop ( source ) if isfuture ( source ) else None dest_loop = _get_loop ( destination ) if isfuture ( destination ) else None def _set_state ( future , other ) : if isfuture ( future ) : _copy_future_state ( other , future ) else : _set_concurrent_future_state ( future , other ) def _call_check_cancel ( destination ) : if destination . cancelled ( ) : if source_loop is None or source_loop is dest_loop : source . cancel ( ) else : source_loop . call_soon_threadsafe ( source . cancel ) def _call_set_state ( source ) : if ( destination . cancelled ( ) and dest_loop is not None and dest_loop . is_closed ( ) ) : return if dest_loop is None or dest_loop is source_loop : _set_state ( destination , source ) else : dest_loop . call_soon_threadsafe ( _set_state , destination , source ) destination . add_done_callback ( _call_check_cancel ) source . add_done_callback ( _call_set_state )