Add `flush_messages` function and remove `EventReceiver` type

This simplifies the API and makes message flushing more generic.
Update examples