Factor out buffer event loop.