I have a sleep function to simulate some actions spending much time.
function sleep(ms) { const startTime = new Date; while (new Date - startTime <