title: How to wait for a flow to complete emitting the values
body: <p>I have a function &quot;getUser&quot; in my Repository which emits an object representing a user based on the provided id.</p>
  <p><a href="https://i.stack.imgur.com/hYFS6.png" rel="nofollow noreferrer">flow function</a></p>
  <pre><code>fun getUser(id: String) = callbackFlow {
      val collectionReference: CollectionReference =
          FirebaseFirestore.getInstance().collection(COLLECTION_USERS)
  
      val query: Query = collectionReference.whereEqualTo(ID, id)
  
      query.get().addOnSuccessListener {
          val lst = it.toObjects(User::class.java)
          if (lst.isEmpty())
              offer(null)
          else
              offer(it.toObjects(User::class.java)[0])
      }
  
      awaitClose()
  }
  </code></pre>
  <p>I need these values in another class. I loop over a list of ids and I add the collected user to a new list. How can I wait for the list to be completed when I collect the values, before calling return?</p>
  <p><a href="https://i.stack.imgur.com/hGqwX.png" rel="nofollow noreferrer">collector function</a></p>
  <pre><code>private fun computeAttendeesList(reminder: Reminder): ArrayList&lt;User&gt; {
      val attendeesList = arrayListOf&lt;User&gt;()
      for (friend in reminder.usersToShare) {
          repoScope.launch {
              Repository.getUser(friend).collect {
                  it?.let { user -&gt;
                      if (!attendeesList.contains(user))
                          attendeesList.add(user)
                  }
              }
          }
      }
      return attendeesList
  }
  </code></pre>
  <p>I do not want to use live data since this is not a UI-related class.</p>