Skip to content

Commit 9cd2acb

Browse files
committed
Kotlin 1.3 and Kotlinx.Coroutines 1.0
2 parents 4822d57 + 41473bf commit 9cd2acb

File tree

5 files changed

+48
-60
lines changed

5 files changed

+48
-60
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# CHANGELOG
22

3-
## Version 0.13.0-eap13 (2017-10-10)
3+
## Version 1.0.0 (2018-13-19)
4+
5+
- kotlinx.coroutines 1.0.1
6+
- Compiled against Kotlin 1.3.11
7+
8+
## Version 0.13.0-eap13 (2018-10-10)
49

510
- kotlinx.coroutines 0.30.2-eap13
611
- Compiled against Kotlin 1.3.0-rc-146
712

8-
## Version 0.13.0 (2017-10-10)
13+
## Version 0.13.0 (2018-10-10)
914

1015
- [kotlinx.coroutines 0.30.2](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.30.2)
1116
- Compiled against Kotlin 1.2.71
1217

18+
## Version 0.12.0-eap13 (2018-08-04) - Stable coroutines
19+
20+
First version of kotlin-coroutines-retrofit based on stable coroutines API from Kotlin 1.3
21+
Compiled against Kotlin 1.3-M1 and kotlinx.coroutines 0.24.0-eap13 (also based on stable API)
22+
23+
1324
## Version 0.12.0 (2017-08-04)
1425

1526
- [kotlinx.coroutines 0.24.0](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.24.0)

README.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,18 @@ This is a small library that provides the [Kotlin Coroutines](https://github.com
88

99
Based on [kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines) implementation.
1010

11-
## Download
12-
13-
Download the [JAR](https://bintray.com/gildor/maven/kotlin-coroutines-retrofit#files/ru/gildor/coroutines/kotlin-coroutines-retrofit):
14-
15-
### If you use Kotlin 1.2: Version of the library based on experimental coroutines API
16-
17-
Gradle:
11+
New version of library (after 1.0.0) support only Kotlin 1.3
1812

19-
```groovy
20-
compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.13.0'
21-
```
22-
23-
Maven:
13+
Kotlin 1.2 and experimental coroutines are not supported anymore, but you can use version `0.13.0` for old projects.
2414

25-
```xml
26-
<dependency>
27-
<groupId>ru.gildor.coroutines</groupId>
28-
<artifactId>kotlin-coroutines-retrofit</artifactId>
29-
<version>0.13.0</version>
30-
</dependency>
31-
```
32-
33-
### If you use Kotlin 1.3: Version based on stable coroutines API
15+
## Download
3416

17+
Download the [JAR](https://bintray.com/gildor/maven/kotlin-coroutines-retrofit#files/ru/gildor/coroutines/kotlin-coroutines-retrofit):
3518

3619
Gradle:
3720

3821
```groovy
39-
compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.13.0-eap13'
22+
compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:1.0.0'
4023
```
4124

4225
Maven:
@@ -45,7 +28,7 @@ Maven:
4528
<dependency>
4629
<groupId>ru.gildor.coroutines</groupId>
4730
<artifactId>kotlin-coroutines-retrofit</artifactId>
48-
<version>0.13.0-eap13</version>
31+
<version>1.0.0</version>
4932
</dependency>
5033
```
5134

build.gradle.kts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
1212
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
1313

1414
plugins {
15-
id("org.jetbrains.kotlin.jvm") version "1.2.71"
15+
id("org.jetbrains.kotlin.jvm") version "1.3.11"
1616
id("com.jfrog.bintray") version "1.8.4"
1717
jacoco
1818
`maven-publish`
1919
id("org.jetbrains.dokka") version "0.9.16"
2020
}
2121

2222
group = "ru.gildor.coroutines"
23-
version = "0.13.0"
23+
version = "1.0.0"
2424
description = "Provides Kotlin Coroutines suspendable await() extensions for Retrofit Call"
2525

2626
repositories {
@@ -34,15 +34,11 @@ java {
3434

3535
dependencies {
3636
compile("org.jetbrains.kotlin:kotlin-stdlib")
37-
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0")
37+
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1")
3838
compile("com.squareup.retrofit2:retrofit:2.4.0")
3939
testCompile("junit:junit:4.12")
4040
}
4141

42-
kotlin {
43-
experimental.coroutines = Coroutines.ENABLE
44-
}
45-
4642
/* Code coverage */
4743

4844
val jacocoTestReport by tasks.getting(JacocoReport::class) {
@@ -81,7 +77,7 @@ val releaseTag = "v${project.version}"
8177
val sourcesJar by tasks.creating(Jar::class) {
8278
dependsOn("classes")
8379
classifier = "sources"
84-
from(sourceSets["main"].allSource)
80+
from(sourceSets["main"].allJava)
8581
}
8682

8783
val javadocJar by tasks.creating(Jar::class) {

src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
package ru.gildor.coroutines.retrofit
1818

19-
import kotlinx.coroutines.experimental.CancellableContinuation
20-
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
19+
import kotlinx.coroutines.CancellableContinuation
20+
import kotlinx.coroutines.suspendCancellableCoroutine
2121
import retrofit2.Call
2222
import retrofit2.Callback
2323
import retrofit2.HttpException
2424
import retrofit2.Response
25+
import kotlin.coroutines.resume
26+
import kotlin.coroutines.resumeWithException
2527

2628
/**
2729
* Suspend extension that allows suspend [Call] inside of a coroutine.
@@ -32,18 +34,14 @@ public suspend fun <T : Any> Call<T>.await(): T {
3234
return suspendCancellableCoroutine { continuation ->
3335
enqueue(object : Callback<T> {
3436
override fun onResponse(call: Call<T>?, response: Response<T?>) {
35-
if (response.isSuccessful) {
36-
val body = response.body()
37-
if (body == null) {
38-
continuation.resumeWithException(
39-
NullPointerException("Response body is null: $response")
40-
)
37+
continuation.resumeWith(runCatching {
38+
if (response.isSuccessful) {
39+
response.body()
40+
?: throw NullPointerException("Response body is null: $response")
4141
} else {
42-
continuation.resume(body)
42+
throw HttpException(response)
4343
}
44-
} else {
45-
continuation.resumeWithException(HttpException(response))
46-
}
44+
})
4745
}
4846

4947
override fun onFailure(call: Call<T>, t: Throwable) {
@@ -91,7 +89,7 @@ public suspend fun <T : Any> Call<T>.awaitResult(): Result<T> {
9189
return suspendCancellableCoroutine { continuation ->
9290
enqueue(object : Callback<T> {
9391
override fun onResponse(call: Call<T>?, response: Response<T>) {
94-
continuation.resume(
92+
continuation.resumeWith(runCatching {
9593
if (response.isSuccessful) {
9694
val body = response.body()
9795
if (body == null) {
@@ -102,7 +100,7 @@ public suspend fun <T : Any> Call<T>.awaitResult(): Result<T> {
102100
} else {
103101
Result.Error(HttpException(response), response.raw())
104102
}
105-
)
103+
})
106104
}
107105

108106
override fun onFailure(call: Call<T>, t: Throwable) {

src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
package ru.gildor.coroutines.retrofit
1818

19-
import kotlinx.coroutines.experimental.CoroutineScope
20-
import kotlinx.coroutines.experimental.Unconfined
21-
import kotlinx.coroutines.experimental.async
22-
import kotlinx.coroutines.experimental.runBlocking
19+
import kotlinx.coroutines.CoroutineScope
20+
import kotlinx.coroutines.Dispatchers
21+
import kotlinx.coroutines.ExperimentalCoroutinesApi
22+
import kotlinx.coroutines.async
23+
import kotlinx.coroutines.runBlocking
2324
import org.junit.Assert.assertEquals
2425
import org.junit.Assert.assertFalse
2526
import org.junit.Assert.assertNull
@@ -32,10 +33,10 @@ import retrofit2.HttpException
3233
import ru.gildor.coroutines.retrofit.util.MockedCall
3334
import ru.gildor.coroutines.retrofit.util.NullBodyCall
3435
import ru.gildor.coroutines.retrofit.util.errorResponse
35-
import kotlin.coroutines.experimental.coroutineContext
3636

3737
private const val DONE = "Done!"
3838

39+
@ExperimentalCoroutinesApi
3940
class CallAwaitTest {
4041
@Test
4142
fun asyncSuccess() = testBlocking {
@@ -260,7 +261,7 @@ class CallAwaitTest {
260261
autoStart = false,
261262
cancelException = IllegalStateException()
262263
)
263-
val async = async(coroutineContext, block = { block(request) })
264+
val async = async(Dispatchers.Unconfined, block = { block(request) })
264265
//We shouldn't crash on cancel exception
265266
try {
266267
assertFalse(request.isCanceled)
@@ -276,7 +277,7 @@ class CallAwaitTest {
276277
exception = IllegalArgumentException(),
277278
autoStart = false
278279
)
279-
val result = async(coroutineContext) {
280+
val result = async(Dispatchers.Unconfined) {
280281
block(request)
281282
}
282283
result.cancel()
@@ -288,14 +289,13 @@ class CallAwaitTest {
288289
block: suspend (Call<String>) -> T
289290
) = testBlocking {
290291
val request = MockedCall(DONE, autoStart = false)
291-
val async = async(coroutineContext) { block(request) }
292+
val async = async(Dispatchers.Unconfined) { block(request) }
292293
assertFalse(request.isCanceled)
293294
async.cancel()
294295
assertTrue(request.isCanceled)
295296
}
297+
298+
private fun testBlocking(block: suspend CoroutineScope.() -> Unit) {
299+
runBlocking(block = block)
300+
}
296301
}
297-
298-
private fun testBlocking(block: suspend CoroutineScope.() -> Unit) {
299-
runBlocking(Unconfined, block)
300-
}
301-

0 commit comments

Comments
 (0)