While this introduces some code duplicates, it seems to be the easy way without rewriting the whole example.
flush()