title: Is there a way to pause or delay an event handler in JavaScript?
body: <p>I'm very new to <strong>JavaScript</strong> and trying to learn. I am using the <em><strong>StreamLabs API</strong></em> to display <code>gif animations</code> for <em>Twitch alerts</em>.</p>
  <p>If alerts come in too quickly, the animation will keep cutting itself off and starting from the beginning. I'm trying to <code>delay</code> the events so that the animations will play fully.</p>
  <p>Currently, the code snippet in question looks like this.</p>
  <pre class="lang-js prettyprint-override"><code>streamlabs.on('event', (eventData) =&gt; 
    {
      var start = new Date();
      if (eventData.for === 'twitch_account') 
      {
        switch (eventData.type) 
        {
          case 'follow':
            //code to handle follow events
            console.log(eventData.message);
            setTimeout(function()
            {
              changeWithFollow();
              setTimeout(function () 
              {
                changeToDefault()
              }, followGifLength);
            }, start % 2500);
            break;
      }
  }
  })
  
  </code></pre>