Skip to content

Commit

Permalink
Update type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Oct 18, 2024
1 parent 710ce94 commit e004ca2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client

Expand Down Expand Up @@ -225,7 +225,7 @@ public class HttpClient(
@Suppress("UNCHECKED_CAST")
val plugin = installedFeatures[key as AttributeKey<Any>]

if (plugin is Closeable) {
if (plugin is AutoCloseable) {
plugin.close()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.engine

import io.ktor.util.*
import io.ktor.utils.io.core.*
import kotlinx.atomicfu.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
Expand Down Expand Up @@ -39,19 +38,4 @@ public abstract class HttpClientEngineBase(private val engineName: String) : Htt
public class ClientEngineClosedException(override val cause: Throwable? = null) :
IllegalStateException("Client already closed")

/**
* Closes [CoroutineDispatcher] if it's [CloseableCoroutineDispatcher] or [Closeable].
*/
@OptIn(ExperimentalCoroutinesApi::class)
private fun CoroutineDispatcher.close() {
try {
when (this) {
is CloseableCoroutineDispatcher -> close()
is Closeable -> close()
}
} catch (ignore: Throwable) {
// Some closeable dispatchers like Dispatchers.IO can't be closed.
}
}

internal expect fun ioDispatcher(): CoroutineDispatcher
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.server.application

import io.ktor.server.routing.*
import io.ktor.util.*
import io.ktor.util.internal.*
import io.ktor.util.pipeline.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.*

/**
Expand Down Expand Up @@ -230,7 +229,7 @@ public fun <A : Pipeline<*, PipelineCall>, B : Any, F : Any> A.uninstall(
public fun <A : Pipeline<*, PipelineCall>, F : Any> A.uninstallPlugin(key: AttributeKey<F>) {
val registry = attributes.getOrNull(pluginRegistryKey) ?: return
val instance = registry.getOrNull(key) ?: return
if (instance is Closeable) {
if (instance is AutoCloseable) {
instance.close()
}
registry.remove(key)
Expand Down

0 comments on commit e004ca2

Please sign in to comment.