var time_begin = new Date().getTime(); while(true){ if(new Date().getTime()-time_begin > 500) break; }