How to synchronized and return inner Listener from this kotlin function which include function inside?


fun getListOfPlaces() : List<String> {
    Log.d("TAG", "Before attaching the listener!");
    val places = ArrayList<String>()
    placesRef.get().addOnCompleteListener { task ->
        if (task.isSuccessful) {
            Log.d("TAG", "Inside onComplete function!");
            for (document in task.result) {
                val name =["name"].toString()
    Log.d("TAG", "After attaching the listener!");
    return list;

And the logcat would be

Before attaching the listener!

After attaching the listener!

Inside onComplete function!

I want to make this function as synchronized as

Before -> Inside -> After.

How can i do it?