Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxyu committed May 15, 2021
1 parent fe42d0a commit b93e2cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# 依赖版本
| Dependency | Version |
|--|--|
| kotlin | 1.4.21 |
| kotlinx-coroutines-android | 1.4.2 |
| kotlin | 1.4.32 |
| kotlinx-coroutines-android | 1.4.3 |
| retrofit | 2.9.0 |

# Gradle 依赖
Expand All @@ -26,7 +26,7 @@ allprojects {

```kotlin
dependencies {
implementation 'com.github.chenxyu:retrofit-adapter-flow:1.1.3'
implementation 'com.github.chenxyu:retrofit-adapter-flow:1.1.4'
}
```

Expand Down
4 changes: 2 additions & 2 deletions adapter-flow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 10
versionName "1.1.3"
versionCode 11
versionName "1.1.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.sendBlocking
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import retrofit2.Call
Expand Down Expand Up @@ -34,8 +35,12 @@ internal class FlowCallAdapter<R>(private val responseType: Type) :
if (body == null || response.code() == 204) {
cancel(CancellationException("HTTP status code: ${response.code()}"))
} else {
offer(body)
channel.close()
try {
sendBlocking(body)
close()
} catch (e: Exception) {
cancel(CancellationException(e.localizedMessage, e))
}
}
} else {
cancel(CancellationException(errorMsg(response) ?: "unknown error"))
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.21'
ext.kotlinx_coroutines_version = '1.4.2'
ext.kotlin_version = '1.4.32'
ext.kotlinx_coroutines_version = '1.4.3'
repositories {
google()
jcenter()
Expand Down

0 comments on commit b93e2cb

Please sign in to comment.