title: how can i stop node-cron schedule in 'while-loop'
body: <p>I want to get response for a specific url using node-cron.</p>
  <p>As in the example code below, 'scheduler' requests to specific url every 10 seconds.</p>
  <p>However, I want this action to be performed only 10 times.</p>
  <p>(There may be other ways, but I definitely want to use the 'start' and 'stop' methods of node-crone.)</p>
  <p>I really want to use the while statement.. The code I wrote doesn't wait for the response of the 'start' method, and as a result, an infinite loop is executed.</p>
  <p>I'll leave the code I wrote below, so if you have a solution, please reply. thanks!!</p>
  <pre><code>import cron from 'node-cron';
  import axios from 'axios';
  import fsPromise from 'fs/promises';
  
  let cronCnt = 0;
  const cronSchedule = cron.schedule(
    '*/10 * * * * *,',
    async () =&gt; {
      try {
        const result = await axios.get(options);
        await fsPromise.writeFile(path, result.data, { encoding: 'utf-8' });
        cronCnt += 1;
      } catch (e) {
        console.error(e);
      }
    },
    {
      scheduled: false,
    },
  );
  
  (async () =&gt; {
    while (true) {
      if (cronCnt &lt; 10) {
        await cronSchedule.start(); // i know.. 'cron.start()' doesnt'return promise... :(
      } else {
        await cronSchedule.stop(); // i know.. 'cron.stop()' doesnt'return promise... :(
        break;
      }
    }
  })();
  
  </code></pre>