coroutine_execution_contexts.md: Add a simple example to clarify what the main usage pattern is

This commit is contained in:
Karol Lewandowski 2025-02-13 11:42:25 +01:00
parent 33dbce0bb0
commit 268e780d5c

View File

@ -51,9 +51,21 @@ Therefore, if their behavior is required, [switch to a blocking context](#suspen
- [`ProgressStep`](%gh-ic%/platform/util/progress/src/impl/ProgressStep.kt) - a step-based progress reporting (see its KDoc for details)
- [`RawProgressReporter`](%gh-ic%/platform/util/progress/src/RawProgressReporter.kt) - a raw text, details, and fraction reporting (invoked via [`reportRawProgress()`](%gh-ic%/platform/util/progress/src/steps.kt))
Any [`report*Progress()`](%gh-ic%/platform/util/progress/src/steps.kt) function should be used inside [`with*Progress()` or `runWithModalProgressBlocking()`](%gh-ic%/platform/progress/shared/src/tasks.kt).
Any [`report*Progress()`](%gh-ic%/platform/util/progress/src/steps.kt) function must be used inside [`withBackgroundProgress()`, `withModalProgress()`, or `runWithModalProgressBlocking()`](%gh-ic%/platform/progress/shared/src/tasks.kt).
Otherwise, if there is no reporter in the context, using `report*Progress()` will have no effect.
Example:
```kotlin
withBackgroundProgress(...) { // or withModalProgress/runWithModalProgressBlocking
// ...
reportProgress { reporter -> // or another report*Progress
// do tasks and report progress
}
// ...
}
```
### Switching to Other Contexts
{#suspending-context-switching-to-other-contexts}