title: Scroll to load: semaphore or bool?
body: <p>I have a tableView. Whenever it displays its last cell it loads more content into it (older posts).</p>
  
  <p>If there's no more posts, then the app sets a bool which prevents more load requests.</p>
  
  <p>However, if the user scrolls up-down fast a few times, the app gets a lot of load requests an crashes.</p>
  
  <p>I would like to prevent that, by using a bool:</p>
  
  <p>So if the app gets a new load-request while the first load-request is still on-going, then I'd like to cancel it.</p>
  
  <p>Bools are working fine, but I heard that semaphores are safer / better.</p>
  
  <hr>
  
  <p>Should I use semaphores? If so, is there a way to not to put a semaphore into waiting, instead if there's an already ongoing process, cancel?</p>
  
  <pre><code>func loadPosts(){
  
      if (isLoadingMoreScrollContent){
          return
      }
  
      self.isLoadingMoreScrollContent = true // THE BOOL
  
      self.activityIndicator.startAnimating()
  
      self.profileFunctions.loadMorePosts(lastLoadedPostId: self.lastLoadedPostId) { response, posts in
          DispatchQueue.main.async {
              if let response = response {
  
                  bla bla... adding the posts
  
              }
  
              self.activityIndicator.stopAnimating()
  
              self.isLoadingMoreScrollContent = false // THE BOOL                
          }
      }
  }
  </code></pre>