Hi! This block of code has `inappropriate blocking...
# android
t
Hi! This block of code has
inappropriate blocking method call
warning. Does anyone know why?
Copy code
CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
    try {
        network.socketFactory.createSocket().use {
            it.connect(InetSocketAddress("8.8.8.8",53),1500)
            validNetworks.add(network)
            checkNetwork()
        }
    }
    catch (e:Exception){
        Timber.e(e)
    }
}
n
Why you use block
use
? Did you need close the socket after end of
checkNetwork()
?
t
Yes I want to close it
e
Each of the method inside the
launch
should be cancellable so that once the coroutine is canceled, the execution will be canceled gracefully. Please check your use of the socket and see if any part of it is not cancellable.
t
I changed to use suspendable methods instead. Thanks
b
This was a bug fir a while, but looks like it was fixed very recently. https://youtrack.jetbrains.com/issue/KTIJ-838