in this code, everything is working fine but when i run code without using settimeout (inside promise) it does not work as it works initially. please explain reason for this