title: How to fix infinite while loop when trying to get batch of tweets using Twit
body: <p>I'm using the Twit npm package to retrieve tweets from a user timeline. The way to get multiple batches of tweets is you have to change max_id of parameters to Twitter API. I'm just testing to get my while loop to work but it is infinite because I don't know how to wait for get function to finish.</p>
  <pre><code>const twitParams = {
          screen_name: username,
          exclude_replies: false,
          include_rts: false,
          trim_user: true,
          count: 200
      };
  
  const allTweetsText = [];
  
  while (allTweetsText.length &lt;= 500) {
      twitClient.get(&quot;statuses/user_timeline&quot;, twitParams, (error, tweets, res) =&gt; {
          for (tweet of tweets) {
              allTweetsText.push(tweet.text);
              console.log(allTweetsText.length);
          }
      });
  }
  </code></pre>
  <p>I never hit the console log becuase it goes back to the top of the loop to check the condition again which never changes resulting in an infinite loop. How can I fix this so the get function finishes before checking the condition again?</p>