title: Executing function calls sequentially
body: <p>I am trying to fetch user input everytime the user edits the textfield and search users according to the input. In the beginning of the search function, I remove the users array and perform the search. However, the function is called concurrently and it empties the array even before performing the search. This might result in duplicate data in the user array. Is there a way to serialize the whole function call? I looked through GCD documents and tried to implemented some methods, but it didn't work out. </p>
  
  <p>This is the source code </p>
  
  <pre><code> // handles editting movement of the search textfield
  @objc func textIsChanging(){
      //need to serialize execution to avoid concurrency.
      // wait until previous call completes? 
      searchUsers()
  
  }
  
  // search user from database.
  private func searchUsers(){
      // empty user array and reload table view
      removeUsers()
      if let searchText = searchField.text?.lowercased() {
          // search with starting index..
          Api.User.queryUsersWithStartText(withText: searchText) { (user) in
              if(CurrentUserInfo.uid != user.uid){
                  self.users.append(user)
                  self.tableView.reloadData()
              }
          }
      }
  }
  </code></pre>