Javascript While Loop Asynchronous Development