Wait for writeStream to finish before proceeding.