Handle truncated responses

    :param callback:
    :param params:
    :param entities:

    :return:

def handle_truncated_response(callback, params, entities):
    """
    Handle truncated responses

    :param callback:
    :param params:
    :param entities:

    :return:
    """
    results = {}
    for entity in entities:
        results[entity] = []
    while True:
        try:
            marker_found = False
            response = callback(**params)
            for entity in entities:
                if entity in response:
                    results[entity] = results[entity] + response[entity]
            for marker_name in ['NextToken', 'Marker', 'PaginationToken']:
                if marker_name in response and response[marker_name]:
                    params[marker_name] = response[marker_name]
                    marker_found = True
            if not marker_found:
                break
        except Exception as e:
            if is_throttled(e):
                time.sleep(1)
            else:
                raise e
    return results