From fcf12f09d2238fe652c25d4c52e3de4201f9afa7 Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 15 Feb 2022 17:09:25 +0100 Subject: [PATCH] Request: fix coroutine pool for server data --- app/src/main/java/dev/lowrespalmtree/comet/Request.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/dev/lowrespalmtree/comet/Request.kt b/app/src/main/java/dev/lowrespalmtree/comet/Request.kt index 51c0aba..cb4dc39 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/Request.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/Request.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.net.Uri import android.util.Log import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.launch import java.io.BufferedInputStream @@ -46,13 +47,12 @@ class Request(private val uri: Uri, private val keyManager: KeyManager? = null) socket.outputStream.write("$uri\r\n".toByteArray()) val channel = Channel() - scope.launch { + scope.launch(Dispatchers.IO) { val buffer = ByteArray(1024) var numRead: Int socket.inputStream.use { socket_input_stream -> BufferedInputStream(socket_input_stream).use { bis -> try { - @Suppress("BlockingMethodInNonBlockingContext") // what u gonna do while ((bis.read(buffer).also { numRead = it }) >= 0) { val received = buffer.sliceArray(0 until numRead) channel.send(received)