title: jquery - execute function call after block of code is completed (which contains animation)
body: <p>Always had trouble with how this works and never really got familiar with the 'correct' way to do this.  This is a small section of larger code, but the same idea applies.  Everywhere <code>App.updatePerfectScrollbar(psSidebar);</code> is called I need to make sure it waits till the lines above it have completed.  There is animation happening, both jquery and css, and  <code>App.updatePerfectScrollbar(psSidebar);</code> should not execute before those animations complete.</p>
  <p>The code as is works, but not as it should as <code>App.updatePerfectScrollbar(psSidebar);</code> is executing before the animations happening before it have completed.</p>
  <p>I do know how long each animation is and nothing is more than 200ms, but I know timeout is not the answer as you cannot be sure it finished.  Is there a way to do a .done() or .promise() type method in this case?</p>
  <pre><code>$('#rlogo').on('click', '.rsideleft-toggler', function(e) {
      
      //if large screen view
      if( $('#sidebar-check').is(':visible') ){
          //toggle minimized sidebar
          if( $('body').hasClass('minimized') ) {
              $('body').removeClass('minimized');
              //show open submenus
              App.sidebarHideSubs(false, 200, 0);
              App.updatePerfectScrollbar(psSidebar); //**** only when above it is finished
          } else {
              $('body').addClass('minimized');
              //show open submenus
              App.sidebarHideSubs(true, 200, 0);
              App.updatePerfectScrollbar(psSidebar); //**** only when above it is finished            
          }
      }
      //mobile view so the button needs to show sidebar and wait for click to go to page or close it
      else {
          //toggle mobileshow sidebar
          if( $('body').hasClass('mobileshow') ) {
              //close it
              $('body').removeClass('mobileshow');
              //close open submenus
              if( $('body').hasClass('minimized') ) {
                  App.sidebarHideSubs(true, 0, 200);
              }
              App.updatePerfectScrollbar(psSidebar); //**** only when above it is finished
          } else {
              //show it
              $('body').addClass('mobileshow');
              //show open submenus
              App.sidebarHideSubs(false, 0, 0);
              App.updatePerfectScrollbar(psSidebar); //**** only when above it is finished
          }
      }
  });
  </code></pre>