From e004ca24ebcea39be17a45cfe989e0225d4f2aac Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Fri, 18 Oct 2024 14:38:32 +0200 Subject: [PATCH] Update type checks --- .../common/src/io/ktor/client/HttpClient.kt | 6 +++--- .../client/engine/HttpClientEngineBase.kt | 20 ++----------------- .../server/application/ApplicationPlugin.kt | 7 +++---- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt index 043f80d781c..9b7c3c8b373 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt @@ -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 @@ -225,7 +225,7 @@ public class HttpClient( @Suppress("UNCHECKED_CAST") val plugin = installedFeatures[key as AttributeKey] - if (plugin is Closeable) { + if (plugin is AutoCloseable) { plugin.close() } } diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt index 0ac6ebc76fb..8c7ec428928 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt @@ -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.* @@ -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 diff --git a/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt b/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt index f38ce7ea430..6f8012d4664 100644 --- a/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt +++ b/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt @@ -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.server.application @@ -8,7 +8,6 @@ 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.* /** @@ -230,7 +229,7 @@ public fun , B : Any, F : Any> A.uninstall( public fun , F : Any> A.uninstallPlugin(key: AttributeKey) { 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)