'Deserialize with Futures'

def _deserialize(self, recvd, load):

    f = self._Future()
    def _chain(_):
        'Chain    result    through    serialization    to    recvd'
        if f.done():
            return
        if recvd.exception():
            f.set_exception(recvd.exception())
        else:
            buf = recvd.result()
            try:
                loaded = load(buf)
            except Exception as e:
                f.set_exception(e)
            else:
                f.set_result(loaded)
    recvd.add_done_callback(_chain)
    def _chain_cancel(_):
        'Chain    cancellation    from    f    to    recvd'
        if recvd.done():
            return
        if f.cancelled():
            recvd.cancel()
    f.add_done_callback(_chain_cancel)
    return f
