title: Function doesn't change the variable when I return Kotlin
body: <p>I am retrieving the data from Firebase Database and I am able to successfully get it, yet when I create a variable in my function to return it returns null, evens though when I debug I can see that I have retrieved the data on Datasnapshot, yet the placesList array when its returned is null!
  I am using MVVM architecture, and cant get why the function doesn't return the value while its being read inside the onDataChange lampda!</p>
  <p>Here is my code</p>
  <pre><code>    fun getAllPlacesFromFireBase(): ArrayList&lt;Place&gt;  {
      var placesList : ArrayList&lt;Place&gt; = ArrayList()
  
      firebaseDatabase.child(&quot;Best Locations&quot;).addValueEventListener(object : ValueEventListener{
          override fun onDataChange(snapshot: DataSnapshot) {
              if (snapshot.exists()){
                  for (placesSnapShot in snapshot.children){
                      val place = placesSnapShot.getValue(Place::class.java)
                      placesList.add(place!!)
                  }
              }
          }
  
          override fun onCancelled(error: DatabaseError) {
              Log.e(&quot;Reprository&quot;,error.toString() )
          }
  
      })
      return placesList
  }
  </code></pre>
  <p>when I debug I can see that the value is read and added in placesList.add(place!!)
  still, when I return the places list in the end of the function I see it's null and it didn't get any of the value at all. can someone help me how to solve this, as I have converted to kotlin recently and this was how I e exactly get the data in Java</p>