title: How to run a function inside a event once?
body: <p>I have a function in Angular.js to determine if a user is inactive or active. When the user is active I want to execute a function after a certain time.</p>
  <p>I have it working but the function is currently running in the same numbers as the executed events.
  How can I ensure that this function is executed once each time?</p>
  <pre><code>.run(function($timeout, $document) {
      // console.log('starting run');
  
      // Timeout timer value
      var TimeOutTimerValue = 120000;
  
      // Start a timeout
      var TimeOutThread = $timeout(function() {
          LogoutByTimer();
      }, TimeOutTimerValue);
      var bodyElement = angular.element($document);
  
      angular.forEach(
          [
              'keydown',
              'keyup',
              'click',
              'mousemove',
              'DOMMouseScroll',
              'mousewheel',
              'mousedown',
              'touchstart',
              'touchmove',
              'scroll',
              'focus'
          ],
          function(EventName) {
              bodyElement.bind(EventName, function(e) {
                  TimeOutResetter(e);
              });
          }
      );
  
      function LogoutByTimer() {
          console.log('Logout');
      }
  
      function TimeOutResetter(e) {
          console.log(' ' + e);
  
          $timeout(function() {
              console.log('run this once ');
          }, 2000);
  
          // Stop the pending timeout
          $timeout.cancel(TimeOutThread);
  
          // Reset the timeout
          TimeOutThread = $timeout(function() {
              LogoutByTimer();
          }, TimeOutTimerValue);
      }
  })
  </code></pre>
  <p>It's going about the <code>console.log('run this once')</code> in the function <code>TimeOutResetter(e)</code>.
  How to run that once?</p>
  <p><a href="http://plnkr.co/edit/fWtsXhsdi4ivrmix?preview" rel="nofollow noreferrer">Click here to see it on Plunker</a></p>