def callback_from_future(future):
    """Return a callback that sets a Future's result or exception"""
    def callback(result, error):
        if error:
            future.set_exception(error)
        else:
            future.set_result(result)

    return callback