所以,我在"onBindViewHolder"回收器的适配器方法中运行了这个代码:
launch(UI) {
val bitmapDrawable = loadLargeBitmapDrawable()
imageView.setImageDrawable(bitmapDrawable)
}
Run Code Online (Sandbox Code Playgroud)
这让我的应用程序冻结了几秒钟,锁定了我的主线程.
但后来我改为:
launch { // <- I removed the "UI"
val bitmapDrawable = loadLargeBitmapDrawable()
launch(UI) { //Launch the UI coroutine inside the other
imageView.setImageDrawable(bitmapDrawable)
}
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?协同程序的目的是在同一个线程(UI)中使事物异步吗?有人可以解释为什么我必须在另一个coroutine范围内运行UI协程?
考虑以下函数:
function myFunction {
100
sleep 1
200
sleep 1
300
sleep 1
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它将沿着管道一一发出这些值。
但我想等待所有值发出后再继续。喜欢
myFunction | waitForThePreviousCommandToComplete | Format-Table
Run Code Online (Sandbox Code Playgroud)
我希望上面的格式表接收整个数组,而不是一对一的项目。
在 Powershell 中是否可以实现?
我在FloatingActionButton中有一个PopupMenuButton。但是它的InkWell不是圆形的,它是标准的正方形。我该如何实现?
我有一个方法可以进行一些异步处理并希望它重试 X 次。我如何在 Dart/Flutter 中实现这一目标?