refactor: replace thread with coroutines

This commit is contained in:
andrekir 2023-07-09 09:15:52 -03:00
parent da28c2a3bc
commit 6f4a10e963

View file

@ -2,6 +2,7 @@ package com.geeksville.mesh.repository.radio
import android.content.Context
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.concurrent.handledLaunch
import com.geeksville.mesh.repository.usb.UsbRepository
import com.geeksville.mesh.util.Exceptions
import java.io.BufferedOutputStream
@ -11,8 +12,6 @@ import java.io.OutputStream
import java.net.InetAddress
import java.net.Socket
import java.net.SocketTimeoutException
import kotlin.concurrent.thread
class TCPInterface(service: RadioInterfaceService, private val address: String) :
StreamInterface(service) {
@ -59,8 +58,7 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
}
override fun connect() {
// No need to keep a reference to this thread - it will exit when we close inStream
thread(start = true, isDaemon = true, name = "TCP reader") {
service.serviceScope.handledLaunch {
try {
val a = InetAddress.getByName(address)
debug("TCP connecting to $address")