typescript wait for function to finish before proceeding