Files
Karol Lewandowski d254beda2b Update General Threading Rules to Threading Model (labels and links)
GitOrigin-RevId: 45406f37f0c5387267708a880de123bd7972f5ac
2024-07-30 17:09:14 +00:00

50 lines
1.4 KiB
HTML

<html>
<body>
Reports loops, <code>forEach</code>-like methods, and <code>ContainerUtil.process()</code> with missing cancellation checks.
<p>Runs only within the methods with <code>com.intellij.util.concurrency.annotations.RequiresReadLock</code> annotation.</p>
<p><b>Example:</b></p>
<pre><code lang="kotlin">
@RequiresReadLock
fun doSomething() {
...
for (item in items) {
ProgressManager.checkCanceled() // should be present in the first line
...
}
items.forEach {
ProgressManager.checkCanceled() // should be present in the first line
...
}
...
}
</code></pre>
<p>In the case of nested loops with nothing in between:</p>
<pre><code lang="kotlin">
@RequiresReadLock
fun doSomething() {
...
for (item in items) {
// nothing in between
for (inner in item.inners) {
ProgressManager.checkCanceled() // should be present in the first line of the inner loop only
...
}
}
...
}
</code></pre>
<p>
In blocking context <code>com.intellij.openapi.progress.ProgressManager.checkCanceled()</code> should be used,
while <code>com.intellij.openapi.progress.CoroutinesKt.checkCancelled()</code> should be used in suspending one.
</p>
<p>
See <a href="https://plugins.jetbrains.com/docs/intellij/background-processes.html#cancellation">Background Processes Cancellation</a> in IntelliJ Platform Plugin SDK docs for more details.
</p>
<!-- tooltip end -->
<p><small>New in 2023.1</small>
</body>
</html>