wait for write to finish