foreach async not waiting javascript