Interceptor.Chain.proceed()是线程阻塞方法吗?

问题描述 投票:0回答:1

假设我从OkHttp3创建自己的Interceptor实现:

class MyInterceptor: Interceptor {

    private val gson = Gson()

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        // Will this block the main thread?
        val response = chain.proceed(request)

        return Response.Builder()
            .code(200)
            .request(request)
            .protocol(Protocol.HTTP_1_1)
            .message("OK")
            .body(
                gson.toJson("foo").toResponseBody("application/json".toMediaType())
            )
            .build()
    }
}

chain.proceed()的调用会阻塞主线程吗?这似乎与Retrofit对suspend函数的支持是违反直觉的,后者是在OkHttp3之上构建的。因为我已选择使用拦截器,所以现在是否会失去异步支持?

android okhttp
1个回答
0
投票
对chain.proceed()的调用会阻塞主线程吗?
© www.soinside.com 2019 - 2024. All rights reserved.