Inappropriate blocking method call

this warning appears even when used with IO context. my code:

override fun download(url: String, file: File): Flow<Long> = flow {
        var total: Long = 0
        var count: Long = 0

        withContext(Dispatchers.IO) {
            val client = OkHttpClient()
            val req = Request.Builder().url(url).build()
            val response = client.newCall(req).**execute**()
            val sink: BufferedSink = Okio.buffer(Okio.**sink**(file))

            response.body()?.let {
                while (count != -1L) {
                    count = it.source().**read**(sink.buffer(), 2048)
                    if (count == -1L) break
                    sink.**emit**()
                    total = total.plus(count)
                    withContext(Dispatchers.Default) {
                        emit(total.times(100).div(it.contentLength()))
                    }
                }
            }
            sink.**close**()
        }
    }

the bold parts are getting warning. is anything going wrong with code or the warning should not appear?



Read more here: https://stackoverflow.com/questions/64894995/inappropriate-blocking-method-call

Content Attribution

This content was originally published by Mahdi M at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: