def METHOD_NAME(task, old_state, new_state):
    if new_state.is_finished():
        map_index = prefect.context.get("map_index")
        if map_index is None:
            map_index = -1
        prefect.RESULTS[(task.slug, map_index)] = new_state.result
    return new_state