"""Teaching baseline: partial target output survives the cancelled reply."""
def render(chunks, cancel_after, destination):
    with destination.open('wb') as target:
        for number, chunk in enumerate(chunks, 1):
            target.write(chunk)
            if cancel_after == number:
                return {'status': 'cancelled', 'published_bytes': 0}
    return {'status': 'completed', 'published_bytes': sum(map(len, chunks))}
