Added auto-flush on timeout in the buffer manager.

Changed the wait() into a wait_for() in the buffer manager so that the
buffer is automatically flushed every N milliseconds even if it is not
full. This is important to guarantee that the data is persisted to
the secondary storage.