瀏覽代碼

Better handling of coroutine cancellations for http calls

Based on https://github.com/tachiyomiorg/tachiyomi-1.x/commit/b94b7eeb6d28a4c3f39488388589fa913c43fe5e
arkon 3 年之前
父節點
當前提交
0afe3011bc
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt

+ 4 - 1
app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt

@@ -9,6 +9,7 @@ import okhttp3.MediaType.Companion.toMediaType
 import okhttp3.OkHttpClient
 import okhttp3.Request
 import okhttp3.Response
+import okhttp3.internal.closeQuietly
 import rx.Observable
 import rx.Producer
 import rx.Subscription
@@ -70,7 +71,9 @@ suspend fun Call.await(): Response {
                         return
                     }
 
-                    continuation.resume(response)
+                    continuation.resume(response) {
+                        response.body?.closeQuietly()
+                    }
                 }
 
                 override fun onFailure(call: Call, e: IOException) {