title: The function runs once, the loop inside it runs 2 times?
body: <p>I simplified the code to explain the problem. When I click the button in my program 3-4 times and the last time I click it, messageStatus = true, the loop runs 3-4 times.</p>
  <pre><code>ipcMain.on('sendMessageMail', async (err, data) =&gt; {
      if (messageStatus) {
          console.log('Stop');
          messageStatus = false;
          return;
      }
  
      if (!messageStatus) {
          console.log('Start');
          messageStatus = true;
      }
  
      for (let i = 0; messageStatus &amp;&amp; i &lt; 100; i++) {
          console.log(i);
          await sleep(1000);
      }
  })
  </code></pre>
  <p><a href="https://i.stack.imgur.com/70IY4.png" rel="nofollow noreferrer">Console Output</a></p>
  <p>What is the problem? Why is the loop running 3-4 times while the event is running once?</p>