title: Promise is blocking the thread
body: <p>I am new to Node.js and was trying to understand <code>async</code> and <code>await</code> terms.</p>
  <p>In the process, I got to know about <code>Promise</code>.</p>
  <p>As I understood, with the help of it, we can make the function non-blocking.</p>
  <p>I tried the following code,
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function get() {
      return new Promise((resolve, reject) =&gt; {
          setTimeout(() =&gt; {
              let out = 0
              const n = 9_900_000
              console.log('start looping')
              for (let i = 0; i &lt; n; i++) {
                  out += Math.cos(i)
              }
              console.log('done looping')
              resolve(out)
              console.log('resolved')
          })
      })
  }
  
  console.log('before function calling')
  r = get()
  console.log('After function calling')
  r.then(console.log)
  console.log('in the end of file')</code></pre>
  </div>
  </div>
  </p>
  <p>We find that <strong><code>get</code> is behaving like a non-blocking function</strong>.</p>
  <hr />
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function get() {
      return new Promise((resolve, reject) =&gt; {
  
          let out = 0
          const n = 9_900_000
          console.log('start looping')
          for (let i = 0; i &lt; n; i++) {
              out += Math.cos(i)
          }
          console.log('done looping')
          resolve(out)
          console.log('resolved')
      })
  }
  console.log('before function calling')
  r = get()
  console.log('After function calling')
  r.then(console.log)
  console.log('in the end of file')</code></pre>
  </div>
  </div>
  </p>
  <p>In other words, I removed the <code>setTimeout</code>.</p>
  <p><strong>Now the <code>get</code> becomes a blocking function.</strong></p>
  <p>Why is this happening?</p>