I need to defer the done <- struct{}{} otherwise even calling flush the program will terminate BEFORE the buffer is completely flushed.