diff --git a/src/main/kotlin/com/viartemev/thewhiterabbit/common/Utlis.kt b/src/main/kotlin/com/viartemev/thewhiterabbit/common/Utlis.kt deleted file mode 100644 index 776573b4..00000000 --- a/src/main/kotlin/com/viartemev/thewhiterabbit/common/Utlis.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.viartemev.thewhiterabbit.common - -import kotlinx.coroutines.CancellableContinuation -import kotlinx.coroutines.CancellationException -import java.io.IOException - -fun cancelOnIOException(cancellableContinuation: CancellableContinuation, block: () -> Unit) { - try { - block() - } catch (e: IOException) { - val cancelled = cancellableContinuation.cancel(e) - if (!cancelled) throw CancellationException(e.message) - } -} diff --git a/src/main/kotlin/com/viartemev/thewhiterabbit/rpc/RpcClient.kt b/src/main/kotlin/com/viartemev/thewhiterabbit/rpc/RpcClient.kt index d7094d74..954436aa 100644 --- a/src/main/kotlin/com/viartemev/thewhiterabbit/rpc/RpcClient.kt +++ b/src/main/kotlin/com/viartemev/thewhiterabbit/rpc/RpcClient.kt @@ -2,7 +2,6 @@ package com.viartemev.thewhiterabbit.rpc import com.rabbitmq.client.Channel import com.viartemev.thewhiterabbit.common.RabbitMqMessage -import com.viartemev.thewhiterabbit.common.cancelOnIOException import com.viartemev.thewhiterabbit.queue.DeleteQueueSpecification import com.viartemev.thewhiterabbit.queue.declareQueue import com.viartemev.thewhiterabbit.queue.deleteQueue @@ -36,15 +35,13 @@ class RpcClient(val channel: Channel) { var consumerTag: String? = null try { return suspendCancellableCoroutine { continuation -> - cancelOnIOException(continuation) { - consumerTag = channel.basicConsume(replyQueueName, true, { _, delivery -> - if (corrId == delivery.properties.correlationId) { - continuation.resume(RabbitMqMessage(delivery.properties, delivery.body)) - } - }, { consumerTag -> - logger.debug { "Consumer $consumerTag has been cancelled for reasons other than by a call to Channel#basicCancel" } - }) - } + consumerTag = channel.basicConsume(replyQueueName, true, { _, delivery -> + if (corrId == delivery.properties.correlationId) { + continuation.resume(RabbitMqMessage(delivery.properties, delivery.body)) + } + }, { consumerTag -> + logger.debug { "Consumer $consumerTag has been cancelled for reasons other than by a call to Channel#basicCancel" } + }) } } finally { try {