Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Ktor update #24

Merged
merged 1 commit into from Sep 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 2 additions & 13 deletions topics/concurrency-and-coroutines.md
Expand Up @@ -156,8 +156,8 @@ commonMain {
}
```

When using other libraries that also depend on `kotlinx.coroutines`, such as Ktor, make sure that they use the single-threaded
version of `kotlinx-coroutines` that works for all platforms. You can do this with `strictly`:
When using other libraries that also depend on `kotlinx.coroutines`, such as Ktor, make sure to specify the multithreaded version
of `kotlinx-coroutines`. You can do this with `strictly`:

```kotlin
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%-native-mt"){
Expand All @@ -177,17 +177,6 @@ If you see `InvalidMutabilityException` related to a coroutine operation, it's v

See a [complete example of using multithreaded coroutines in a KMM application](https://github.com/touchlab/KaMPKit).

### Ktor and coroutines

Follow these guidelines when integrating Ktor into your project:

* Make sure that you use the single-threaded version of `kotlinx.coroutines` as a dependency for Ktor. Ktor
for macOS and iOS requires this version.
* Make calls to Ktor from the main thread.
* If you're going to use Ktor and coroutines that cross threads, keep a separate `CoroutineScope` for Ktor. As a more complex
alternative, you can create a child `CoroutineScope` with an isolated `Job`. If `Job` gets frozen, Ktor will stop working.
See [this example](https://github.com/touchlab/KaMPKit/blob/master/shared/src/iosMain/kotlin/co/touchlab/kampkit/ktor/Platform.kt#L13) for details.

## Alternatives to `kotlinx-coroutines`

There are a few alternative ways to run parallel code.
Expand Down