Javascript While Loop Asynchronous