OK, not very realistic, but it illustrates the point. We keep building up the internal data until some other internal logic determines we're done, at which point we then write out some final bits of data to close the operation.
Now, let's add the dispatchEvent call: