forEach 的方法,以及 ContainerUtil.process()。
仅在具有 com.intellij.util.concurrency.annotations.RequiresReadLock 注解的方法内运行。
示例:
@RequiresReadLock
fun doSomething() {
...
for (item in items) {
ProgressManager.checkCanceled() // 应该出现在第一行中
...
}
items.forEach {
ProgressManager.checkCanceled() // 应该出现在第一行中
...
}
...
}
在嵌套循环之间没有任何内容的情况下:
@RequiresReadLock
fun doSomething() {
...
for (item in items) {
// 之间没有任何内容
for (inner in item.inners) {
ProgressManager.checkCanceled() // 应仅出现在内部循环的第一行中
...
}
}
...
}
在阻塞上下文中应使用 com.intellij.openapi.progress.ProgressManager.checkCanceled(),而在挂起上下文中应使用 com.intellij.openapi.progress.CoroutinesKt.checkCancelled()。
See Background Processes Cancellation in IntelliJ Platform Plugin SDK docs for more details.
2023.1 最新变化