title: `return` code is being executed before Firebase call is finished fetching - swift
body: <p>The following function is suppose to fetch a list of <strong>blocked-users</strong> then fetch <strong>blocked-by-users</strong> merge the two lists and return it as a <code>[String]</code>.</p>
  
  <p>The output to the console is the following which tells me that the <code>return</code> <code>blockedList</code> is being called early - <strong>how can I force for the two observeSingleEvents functions are finished before passing the array back to the caller method?</strong>  </p>
  
  <blockquote>
    <p>1 
    4 
    2 
    3</p>
  </blockquote>
  
  <pre><code>func getBlockedUsersList() -&gt; [String]{
  
      var blockedList = [String]()
      var blockedUsers = [String]()
      var blockedByUsers = [String]()
      print("1")
  
      DataService.run.getBlockedByUsersList { (success, blockedByUsersList) in
          print("2")
          if success {
  
              blockedByUsers = blockedByUsersList
  
              DataService.run.getBlockedUsersList(handler: { (success, blockedUsersList) in
                  print("3")
                  if success {
  
                      blockedUsers = blockedUsersList
  
                      blockedList = Array(Set(blockedUsers + blockedByUsers))
  
                  }//end if-success
  
              })//getBlockedUsersList
  
          }//end if-success
  
      }//end getBlockedByUsersList
  
      print("4")
      return blockedList
  
  }//end func
  </code></pre>
  
  <p><strong>Function <code>getBlockedByUsersList</code> gets list from Firebase:</strong></p>
  
  <pre><code>func getBlockedByUsersList(handler: @escaping (Bool, [String]) -&gt; ()){
  
      guard let uid = Auth.auth().currentUser?.uid else { return }
  
      var blockedUIDs = [String]()
  
      REF_USERS.child(uid).child("blocked-by-users").observeSingleEvent(of: .value, with: { (snapshot) in
  
          for child in snapshot.children{
  
              let itemSnap = child as! DataSnapshot
              blockedUIDs.append(itemSnap.key)
  
          }//end for
  
          handler(true, blockedUIDs)
  
  
      }) { (error) in
          print("error: \(error.localizedDescription)")
      }
  
  }//end func
  </code></pre>