mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
kotlin_coroutines.md: Cleanup
This commit is contained in:
parent
56677722ed
commit
39fb9bed74
@ -8,7 +8,7 @@
|
|||||||
The IntelliJ Platform is a multithreading environment that executes many asynchronous and non-blocking tasks to avoid UI freezes.
|
The IntelliJ Platform is a multithreading environment that executes many asynchronous and non-blocking tasks to avoid UI freezes.
|
||||||
These tasks are usually executed in background threads, which is a standard approach in the JVM world.
|
These tasks are usually executed in background threads, which is a standard approach in the JVM world.
|
||||||
|
|
||||||
Since version 1.1, [Kotlin](using_kotlin.md) has introduced coroutines as a lightweight and easy to implement abstraction over threads.
|
Since version 1.1, [Kotlin](using_kotlin.md) has introduced coroutines as a lightweight and cleaner abstraction over threads, allowing them to be utilized more efficiently.
|
||||||
The IntelliJ Platform started adapting coroutines in its APIs and internal code, and since 2024.1 it is recommended to use the coroutines approach over threads.
|
The IntelliJ Platform started adapting coroutines in its APIs and internal code, and since 2024.1 it is recommended to use the coroutines approach over threads.
|
||||||
|
|
||||||
> Plugins _must_ use the bundled Kotlin Coroutines library, see [](using_kotlin.md#coroutinesLibraries).
|
> Plugins _must_ use the bundled Kotlin Coroutines library, see [](using_kotlin.md#coroutinesLibraries).
|
||||||
@ -18,7 +18,7 @@ The IntelliJ Platform started adapting coroutines in its APIs and internal code,
|
|||||||
### Coroutines Advantages
|
### Coroutines Advantages
|
||||||
|
|
||||||
The reason for coroutines being lightweight is the fact that they aren't bound to OS native threads, as opposed to the JVM threads.
|
The reason for coroutines being lightweight is the fact that they aren't bound to OS native threads, as opposed to the JVM threads.
|
||||||
It enables much less memory consumption and cheaper context switching, which makes the platform and plugins more performant.
|
It enables much less memory consumption and more efficient context switching, which makes the platform and plugins more performant.
|
||||||
For example, it is straightforward to run 100.000 coroutines on a standard computer, which is not possible with threads as it would cause `OutOfMemoryError`.
|
For example, it is straightforward to run 100.000 coroutines on a standard computer, which is not possible with threads as it would cause `OutOfMemoryError`.
|
||||||
|
|
||||||
Besides performance, there are more advantages of using coroutines:
|
Besides performance, there are more advantages of using coroutines:
|
||||||
@ -26,15 +26,13 @@ Besides performance, there are more advantages of using coroutines:
|
|||||||
What was usually implemented with hard to understand, implement, and maintain callbacks, with coroutines looks like regular sequential/imperative code.
|
What was usually implemented with hard to understand, implement, and maintain callbacks, with coroutines looks like regular sequential/imperative code.
|
||||||
- Coroutines allow for implementing structured concurrency (coroutines can spawn child coroutines), which allows for easily managing the lifecycle of concurrent tasks and error handling.
|
- Coroutines allow for implementing structured concurrency (coroutines can spawn child coroutines), which allows for easily managing the lifecycle of concurrent tasks and error handling.
|
||||||
For example, cancelling a parent coroutine automatically cancels all child coroutines.
|
For example, cancelling a parent coroutine automatically cancels all child coroutines.
|
||||||
- It is trivial to switch execution of the code parts between UI and background threads.
|
- It is trivial to switch execution of the code parts between [UI and background threads](threading_model.md).
|
||||||
|
|
||||||
[//]: # (TODO: add links to the specific topics when ready)
|
|
||||||
|
|
||||||
### Java Interoperability
|
### Java Interoperability
|
||||||
|
|
||||||
Coroutines provide very limited Java interoperability, and coroutine-based APIs can’t be used to the full extent from Java code.
|
Coroutines provide very limited Java interoperability, and coroutine-based APIs can’t be used to the full extent from Java code.
|
||||||
|
|
||||||
Kotlin Coroutines are new to the IntelliJ Platform and aren't yet widely adopted in public APIs.
|
Kotlin Coroutines are relatively new to the IntelliJ Platform and aren't yet widely adopted in public APIs.
|
||||||
In the future, the number of coroutine-based APIs will grow, and using only Java may not be enough to implement a fully functional plugin.
|
In the future, the number of coroutine-based APIs will grow, and using only Java may not be enough to implement a fully functional plugin.
|
||||||
It will be required to use [Kotlin](using_kotlin.md), at least partially, for example, to implement coroutine-based [extension points](plugin_extension_points.md).
|
It will be required to use [Kotlin](using_kotlin.md), at least partially, for example, to implement coroutine-based [extension points](plugin_extension_points.md).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user