break loop after time javascript

JavaScript
var keepCalling = true;

setTimeout(function () {
  keepCalling = false;
}, 10000);

while ( keepCalling ) {
  // do something
}
Source

Also in JavaScript: