title: How to wrap it inside setTimeout ? if we assume it will take time to receive data from server(here simply txt file) so execute it after some time
body: <p>How to wrap it inside setTimeout ?
  Suppose instead of taking data from file if we take data from server and it will take some time to give response ?</p>
  
  <pre><code>console.log('Now you are online.');
  function callingfun() {
    return new Promise(function (resolve, reject) {
      let xhr = new XMLHttpRequest();
      xhr.open('GET', 'kk1.txt', true);
  **strong text**
      xhr.onload = function () {
        if (this.status === 200) {
          console.log(this.responseText);
          resolve();
        }
        else {
          console.log('some error occured');
          reject();
        }
      }
      xhr.send();
    })
  }
  
  callingfun().then(function () { console.log('promise resolved'); }).catch(function () { console.log('promise rejected') });
  
  </code></pre>