Serial.flush() waits for the transmission of outgoing serial data to complete. Is that what you are trying to do ?