better flushing

instead of flushing on every write, we only flush after a certain number
of bytes have been written to the channel

additionally, we schedule a task to periodically flush the channel so we
can ensure delivery of all messages written to the channel