kotlin - 如何同步这个包含函数的 kotlin 函数?
问题描述
例子:
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 = document.data["name"].toString()
places.add(name)
}
}
}
Log.d("TAG", "After attaching the listener!");
return list;
}
而logcat将是
Before attaching the listener!
After attaching the listener!
Inside onComplete function!
我想让这个函数与之前 -> 内部 -> 之后一样同步。
我该怎么做?
解决方案
推荐阅读
- javascript - 尝试使用 sequelize 创建迁移时出错
- standby - stm32l4中待机模式不降低功耗,使用RTOS uCOS-III
- python - 使用多个后缀扩展名重命名 CSV 文件
- javascript - 无法在我的 React App 上同时更新多个状态属性
- ruby - 如何读取终端中的最后一行并使用 ruby 将其保存在 var 中
- regex - Ansible 2.5.5 - “替换”模块中的属性之前不起作用
- r - 如何整理字符向量中用下划线分隔的单词
- javascript - 使用链接按钮打印 div ta 的内容
- mongodb - mongodb加减一查询(减去两个查询结果)
- python - Mixer.music.play() 在 mu-editor 中有效,但在终端中无效